Ansible quoting

Victory! I’ll add a few tests for invalid data and send in a pull request.

TEST_FLAGS=“-t test_powershell_filter -i /etc/ansible/hosts” make test_winrm
ansible-playbook test_winrm.yml -i inventory.winrm -e @integration_config.yml -v -t test_powershell_filter -i /etc/ansible/hosts
[WARNING]: The version of gmp you have installed has a known issue regarding
timing vulnerabilities when used with pycrypto. If possible, you should update
it (i.e. yum update gmp).

PLAY [windows] ****************************************************************

TASK: [test_powershell_filter | Convert yaml dict to powershell hash] *********
changed: [mdm-wsrv98.surescripts-dev.qa → 127.0.0.1] => {“changed”: true, “cmd”: “echo ‘@{‘This’=‘THIS’;‘Other’=‘OTHER’;‘That’=‘THAT’;}’”, “delta”: “0:00:00.003494”, “end”: “2015-02-23 15:52:47.477128”, “rc”: 0, “start”: “2015-02-23 15:52:47.473634”, “stderr”: “”, “stdout”: “@{This=THIS;Other=OTHER;That=THAT;}”, “warnings”: }

TASK: [test_powershell_filter | Check that actual equals expected] ************
ok: [mdm-wsrv98.surescripts-dev.qa] => {“msg”: “all assertions passed”}

I updated the test_win_script role in my fork to use the filter and confirm the output matches the expected results.

I recently upgrade to ansible 1.9.2 and am now having issues with the splatting. I looked at https://github.com/cchurch/ansible/blob/e9b6aaf5d8836ce7ffdca855e006c2131fe19632/lib/ansible/runner/shell_plugins/powershell.py since that fixed it last time. THe only change that wasn’t still there was in powershell.py. I made the following change and it works now. I haven’t gone back to debug closer to see what the difference is.

def _build_file_cmd(cmd_parts, quote_args=True):
‘’‘Build command line to run a file, given list of file name plus args.’‘’
if quote_args:
cmd_parts = [‘“%s”’ % x for x in cmd_parts]
#return ’ ‘.join(_common_args + [’-ExecutionPolicy’, ‘Unrestricted’, ‘-File’] + cmd_parts)
return ’ ‘.join([’&'] + cmd_parts)

Before the change this was the output:
TASK: [windowsDeploy | Call deploy.ps1] *************************************** changed: [hostname] => {“changed”: true, “rc”: 0, “stderr”: “C:\Users\l_ansible\AppData\Local\Temp\ansible-tmp-1438627351.4-181936062454137\\r\nwrapper.ps1 : Cannot process argument transformation on parameter \r\n’installArguments’. Cannot convert the "System.Collections.Hashtable" value of \r\ntype "System.String" to type "System.Collections.Hashtable".\r\n + CategoryInfo : InvalidData: (:slight_smile: [wrapper.ps1], ParentContainsEr \r\n rorRecordException\r\n + FullyQualifiedErrorId : ParameterArgumentTransformationError,wrapper.ps1\r\n \r\n”, “stdout”: “”}

I set the debug higher to see the splatted argument and verified it is a correct powershell array/hash. I can fill out an issue at github but thought this would be a good start.

Worth trying current dev if you can as I think the way parameters are passed has changed.

All the best, Jon

I had the same problem and made the change below to fix the issue.

How did you solve the issue (what did you mean by below)? I haven't had time to look into the root cause of this yet.