Home > Enterprise >  Why can't Ansible find an executable that's in the system path?
Why can't Ansible find an executable that's in the system path?

Time:10-02

Ansible v2.11 Target: Windows 2012 Server

I'm trying to unzip a file using the C:\Program Files\7-zip\7z.exe utility, and that folder is in the system path. I can't use win_unzip because of long file names. However I get this?

- name: "Unzip exa-web {{ exa_web_zip }}"
  win_command:
    7z x {{ remote_dir }}/{{ exa_web_zip }} -o{{ exa_web_dir }}

TASK [exa-web : Unzip exa-web exa-web-development-b7cf4eee3c-20210930_1700-win64.zip] ***
fatal: [172.16.100.31]: FAILED! => {"changed": false, "cmd": "7z x C:\\temp/exa-web-development-b7cf4eee3c-20210930_1700-win64.zip -oC:\\Viztek\\EXA\\web", "msg": "Exception calling \"SearchPath\" with \"1\" argument(s): \"Could not find file '7z.exe'.\"", "rc": 2}

I even added this task just to ensure that is is in the system path, to no avail.

- name: Add to system path
  win_path:
    elements:
      - "C:\\Program Filse\\7-zip"

What am I missing?

CodePudding user response:

there is a common parameter you should use, it is called chdir. Then ansible should find the executable:

- name: "Unzip exa-web {{ exa_web_zip }}"
  win_command:
    7z x {{ remote_dir }}/{{ exa_web_zip }} -o{{ exa_web_dir }}
  args:
    chdir: 'C:\Program Filse\7-zip'
  • Related