# error when running a windows command using 'raw'

**URL:** <https://forum.ansible.com/t/error-when-running-a-windows-command-using-raw/31051>\
**Category:** Ansible Developer\
**Tags:** windows, awx\
**Created:** [August 15, 2019, 4:08pm UTC](https://forum.ansible.com/t/error-when-running-a-windows-command-using-raw/31051 "2019-08-15T16:08:28Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chris\_Jackson](https://avatars.discourse-cdn.com/v4/letter/c/8c91f0/32.png) [@Chris\_Jackson](https://forum.ansible.com/u/Chris_Jackson)\
**Post date:** [August 15, 2019, 4:08pm UTC](https://forum.ansible.com/t/error-when-running-a-windows-command-using-raw/31051/1 "2019-08-15T16:08:28Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dnsbob](https://avatars.discourse-cdn.com/v4/letter/d/ea5d25/32.png) [@dnsbob](https://forum.ansible.com/u/dnsbob)\
**Post date:** [August 15, 2019, 8:07pm UTC](https://forum.ansible.com/t/error-when-running-a-windows-command-using-raw/31051/2 "2019-08-15T20:07:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dnsbob](https://avatars.discourse-cdn.com/v4/letter/d/ea5d25/32.png) [@dnsbob](https://forum.ansible.com/u/dnsbob)\
**Post date:** [August 15, 2019, 8:14pm UTC](https://forum.ansible.com/t/error-when-running-a-windows-command-using-raw/31051/3 "2019-08-15T20:14:59Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![jborean](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jborean/32/1525_2.png) [@jborean](https://forum.ansible.com/u/jborean)\
**Post date:** [August 15, 2019, 8:50pm UTC](https://forum.ansible.com/t/error-when-running-a-windows-command-using-raw/31051/4 "2019-08-15T20:50:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jborean](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jborean/32/1525_2.png) [@jborean](https://forum.ansible.com/u/jborean)\
**Post date:** [August 15, 2019, 8:51pm UTC](https://forum.ansible.com/t/error-when-running-a-windows-command-using-raw/31051/5 "2019-08-15T20:51:34Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Chris\_Jackson](https://avatars.discourse-cdn.com/v4/letter/c/8c91f0/32.png) [@Chris\_Jackson](https://forum.ansible.com/u/Chris_Jackson)\
**Post date:** [August 16, 2019, 9:01am UTC](https://forum.ansible.com/t/error-when-running-a-windows-command-using-raw/31051/6 "2019-08-16T09:01:09Z")

</div>

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”:

---

<div class="post-metadata">

**Author:** ![Chris\_Jackson](https://avatars.discourse-cdn.com/v4/letter/c/8c91f0/32.png) [@Chris\_Jackson](https://forum.ansible.com/u/Chris_Jackson)\
**Post date:** [August 16, 2019, 9:06am UTC](https://forum.ansible.com/t/error-when-running-a-windows-command-using-raw/31051/7 "2019-08-16T09:06:03Z")

</div>

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 }}”’

---

<div class="post-metadata">

**Author:** ![jborean](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jborean/32/1525_2.png) [@jborean](https://forum.ansible.com/u/jborean)\
**Post date:** [August 16, 2019, 11:03am UTC](https://forum.ansible.com/t/error-when-running-a-windows-command-using-raw/31051/8 "2019-08-16T11:03:45Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Chris\_Jackson](https://avatars.discourse-cdn.com/v4/letter/c/8c91f0/32.png) [@Chris\_Jackson](https://forum.ansible.com/u/Chris_Jackson)\
**Post date:** [August 16, 2019, 11:42am UTC](https://forum.ansible.com/t/error-when-running-a-windows-command-using-raw/31051/9 "2019-08-16T11:42:31Z")

</div>

Jordan,

Worked like a dream! I changed the module to win\_command.

Many thanks for your help!

Regards

Chris
