error when running a windows command using 'raw'

Hi all,

Tearing my hair out trying to resolve this. I am getting the following:-

“reason”: “failed at splitting arguments, either an unbalanced jinja2 block or quotes: C:\‘Program Files’\IBM\SQLLIB\BIN\db2licm -a\n{{ temp_area }}\{{ db2_lic_file }}\n\nThe error appears to have been in ‘/var/lib/awx/projects/_49__ansible_chrisj_testing/playbooks/MQ_Test/Machine_Setup/roles/DB2_Install/tasks/Win32NT_DB2_Install.yml’: line 51, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - name: Installing the license\n ^ here\n”

This is the errant piece of yaml:-

  • name: Installing the license
    raw: |
    C:'Program Files’\IBM\SQLLIB\BIN\db2licm -a
    {{ temp_area }}{{ db2_lic_file }}

Can anyone help?

Many Thanks

Chris.

My first guess is that the backslash "" characters are ‘escaping’ the following character. Try doubling each of them “\”

Probably not that, it seems to have understood the backslash. It is complaining about the “name:” line, so either there is an invisible character (happens when I cut/paste from a doc or web page), or likely the problem is before that line, so it is not expecting the ‘name:’ line. Can you show us the preceding few lines?

Not sure why it is complaining here, maybe an invisble control character. Anyway you are best off doing the following;

`

  • name: Installing the license
    raw: ‘“C:\Program Files\IBM\SQLLIB\BIN\db2licm” -a “{{ temp_area }}{{ db2_lic_file }}”’

`

Raw in Windows is not truly raw as it is run in a PowerShell shell so the standard quoting rules apply. Having C:'Progam Files’.. wouldn’t work as that isn’t valid PowerShell. The example above will quote that whole string as well as your -a arg in case it has a space in it. You can also consider using win_command for this if you want to talk advantage of things like become, environment, async and some of the other options it adds.

Thanks

Jordan

Actually if your example is literal and -a is on a newline then that’s probably your issue, it sounds like you wanted ‘>’ not ‘|’ to folder each newline in your string but I still recommend the way above I posted.

Thankls for the responses so far.

Getting a different error now after applying your suggestion Jordan (so positive)

“stderr_lines”: [
“At line:1 char:43”,
“+ "C:\Program Files\IBM\SQLLIB\BIN\db2licm" -a "C:\Users\ADMINI~1\AppDa …”,
“+ ~~”,
“Unexpected token ‘-a’ in expression or statement.”,
“At line:1 char:46”,
“+ … \db2licm" -a "C:\Users\ADMINI~1\AppData\Local\Temp\db2_11_aese_u.lic"”,
“+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~”,
“Unexpected token ‘"C:\Users\ADMINI~1\AppData\Local\Temp\db2_11_aese_u.lic"’ in expression or statement.”,
“+ CategoryInfo : ParserError: (:slight_smile: , ParentContainsErrorRecordException”,
“+ FullyQualifiedErrorId : UnexpectedToken”
],
“_ansible_no_log”: false,
“stdout”: “”,
“changed”: true,
“stderr”: “At line:1 char:43\r\n+ "C:\Program Files\IBM\SQLLIB\BIN\db2licm" -a "C:\Users\ADMINI~1\AppDa …\r\n+ ~~\r\nUnexpected token ‘-a’ in expression or statement.\r\nAt line:1 char:46\r\n+ … \db2licm" -a "C:\Users\ADMINI~1\AppData\Local\Temp\db2_11_aese_u.lic"\r\n+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\nUnexpected token ‘"C:\Users\ADMINI~1\AppData\Local\Temp\db2_11_aese_u.lic"’ in expression or statement.\r\n+ CategoryInfo : ParserError: (:slight_smile: , ParentContainsErrorRecordException\r\n+ FullyQualifiedErrorId : UnexpectedToken\r\n”,
“rc”: 1,
“msg”: “non-zero return code”,
“stdout_lines”:

Sorry, just to add to the previous post, the yaml is now as follows:-

  • name: Installing the license
    raw: ‘“C:\Program Files\IBM\SQLLIB\BIN\db2licm” -a “{{ temp_area }}{{ db2_lic_file }}”’

That’s my bad, when you quote the string and want to execute it you need to add the call operator like:

- raw: ‘&” C:\Program Files\... “‘

The alternative is to use win_command with the setup you have right now.

Jordan,

Worked like a dream! I changed the module to win_command.

Many thanks for your help!

Regards

Chris