error when running a windows command using 'raw'

20 views
Skip to first unread message

Chris Jackson

unread,
Aug 15, 2019, 12:08:28 PM8/15/19
to Ansible Development

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.

Bob Harold

unread,
Aug 15, 2019, 4:07:50 PM8/15/19
to Chris Jackson, Ansible Development
My first guess is that the backslash "\" characters are 'escaping' the following character.  Try doubling each of them "\\"

-- 
Bob Harold
 

Bob Harold

unread,
Aug 15, 2019, 4:15:13 PM8/15/19
to Chris Jackson, Ansible Development
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?

-- 
Bob Harold
 

Jordan Borean

unread,
Aug 15, 2019, 4:50:32 PM8/15/19
to Ansible Development
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

Jordan Borean

unread,
Aug 15, 2019, 4:51:34 PM8/15/19
to Ansible Development
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.

Chris Jackson

unread,
Aug 16, 2019, 5:01:09 AM8/16/19
to Ansible Development
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: (:) [], 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: (:) [], ParentContainsErrorRecordException\r\n+ FullyQualifiedErrorId : UnexpectedToken\r\n",
    "rc": 1,
    "msg": "non-zero return code",
    "stdout_lines": []

Chris Jackson

unread,
Aug 16, 2019, 5:06:03 AM8/16/19
to Ansible Development
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 }}"'

On Thursday, August 15, 2019 at 5:08:28 PM UTC+1, Chris Jackson wrote:

Jordan Borean

unread,
Aug 16, 2019, 7:03:45 AM8/16/19
to Ansible Development
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.

Chris Jackson

unread,
Aug 16, 2019, 7:42:31 AM8/16/19
to Ansible Development
Jordan,

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

Many thanks for your help!

Regards

Chris
Reply all
Reply to author
Forward
0 new messages