win_shell failing since Ansible 2.5 (?)

My playbook is broken since i upgraded to v2.5

Here is the simplest example i have:

The code from my playbook:

`

  • name: Install Winzip Package
    win_shell: ‘cmd /C C:\Users\ansible\Downloads\install_winzip.cmd’
    args:
    creates: ‘C:\Program Files\WinZip\WINZIP64.EXE’

`

Here is the output:

`

TASK [common : Install Winzip Package] *****************************************************************************************************************************************************
task path: /ansible/scripts/roles/common/tasks/winzip.yml:11
Using module file /usr/lib/python2.7/dist-packages/ansible/modules/windows/win_shell.ps1
<hasgqba011.DOMAIN> ESTABLISH WINRM CONNECTION FOR USER: ansible@DOMAIN on PORT 5986 TO hasgqba011.DOMAIN
checking if winrm_host hasgqba011.DOMAIN is an IPv6 address
creating Kerberos CC at /tmp/tmpg3ejrJ
calling kinit with subprocess for principal ansible@DOMAIN
kinit succeeded for principal ansible@DOMAIN
<hasgqba011.DOMAIN> WINRM CONNECT: transport=kerberos endpoint=https://hasgqba011.DOMAIN:5986/wsman
<hasgqba011.DOMAIN> WINRM OPEN SHELL: CCE2248A-9096-4242-B51C-9A1911DBBEE9
EXEC (via pipeline wrapper)
<hasgqba011.DOMAIN> WINRM EXEC ‘PowerShell’ [‘-NoProfile’, ‘-NonInteractive’, ‘-ExecutionPolicy’, ‘Unrestricted’, ‘-’]
<hasgqba011.DOMAIN> WINRM RESULT u’<Response code 1, out “”, err “Test-AnsiblePath : E”>’
<hasgqba011.DOMAIN> WINRM CLOSE SHELL: CCE2248A-9096-4242-B51C-9A1911DBBEE9
fatal: [hasgqba011.DOMAIN]: FAILED! => {
“changed”: false,
“module_stderr”: “Test-AnsiblePath : Exception calling "GetAttributes" with "1" argument(s): "Could not find a part of the path \r\n’C:\Program Files\WinZip\WINZIP64.EXE’."\r\nAt line:59 char:21\r\n+ if ($creates -and $(Test-AnsiblePath -Path $creates)) {\r\n+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n + CategoryInfo : NotSpecified: (:slight_smile: [Test-AnsiblePath], MethodInvocationException\r\n + FullyQualifiedErrorId : DirectoryNotFoundException,Test-AnsiblePath\r\n \r\n\r\n”,
“module_stdout”: “”,
“msg”: “MODULE FAILURE”,
“rc”: 1
}

`

I want to install winzip if the file winzip64.exe is not found, and it fails because it’s not found.
Removing the args/creates lines → works like a charm.

Thanks.

Thanks for the report, I am able to replicate this on 2.5 and have raised a Github issue for it https://github.com/ansible/ansible/issues/37967.

The issue is the path C:\Program Files\WinZip does not exist and the Test-AnsiblePath method is throwing a different exception in this case which we should be catching. If ‘C:\Program Files\WinZip’ did exist, then this would still continue to work but alas it isn’t.

I know how to fix it but unfortunately we don’t have a workaround apart either

  • Creating the parent directory in a previous task
  • Using a custom win_shell module that did not use Ansible.ModuleUtils.FileUtil or stay on the previous version until this is fixed.

Thanks

Jordan

Sidenote: here is the PR to fix this issue https://github.com/ansible/ansible/pull/37968

Thanks Jordan!
I am able to bypass this issue by checking the directory with win_stat and use a register as a condition for the win_shell.
I noticed the handlers are now working which is great :slight_smile:

Thanks again!