$ ansible --version
ansible 2.10.8
I have a simple task to list the *.zip file in a Windows folder
- name: Get name of old file
win_command: dir /b *.zip
args:
chdir C:\\temp
and I get
TASK [list-files : Get name of old file] ******************************************
fatal: [10.x.x.x]: FAILED! => {"changed": false, "cmd": "dir /b *.zip", "msg": "Exception calling \"SearchPath\" with \"1\" argument(s): \"Could not find file 'dir.exe'.\"", "rc": 2}
However, this works
ansible -i 10.x.x.x, 10.x.x.x -m win_command -a "cmd.exe /c dir c:\temp\*.zip"
Any clues?
>Solution :
FAIR WARNING: I don’t have a copy of Windows to test this, but still hope it’s helpful…
Since dir is (as the error helpfully explains) not an executable but rather a shell built-in, you’ll want to use win_shell: instead of the command version
As the fine manual points out, the default shell is PowerShell, so ensure you provide the executable: cmd to put it back to the old one if you really want to use that DOS style invocation versus Get-ChildItem -Recursive
- name: Get name of old file
win_shell: dir /b *.zip
args:
executable: cmd
chdir: C:\\temp