# YAML and colons -- cannot escape / quote -- need help

**URL:** <https://forum.ansible.com/t/yaml-and-colons-cannot-escape-quote-need-help/22621>\
**Category:** Ansible Project\
**Created:** [September 22, 2016, 6:29pm UTC](https://forum.ansible.com/t/yaml-and-colons-cannot-escape-quote-need-help/22621 "2016-09-22T18:29:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_Leo\_Huetter](https://avatars.discourse-cdn.com/v4/letter/j/6f9a4e/32.png) [@John\_Leo\_Huetter](https://forum.ansible.com/u/John_Leo_Huetter)\
**Post date:** [September 22, 2016, 6:29pm UTC](https://forum.ansible.com/t/yaml-and-colons-cannot-escape-quote-need-help/22621/1 "2016-09-22T18:29:38Z")

</div>

Hello …

I am invoking puppet agent -t from Ansible, and since some puppet non-zero return codes are OK, I am parsing the stdout to look for errors and fail if any errors are seen.

In this case, the error string I am looking for is “has failures: true”

The string I am looking for has a colon and I cannot for the life of me escape it.

I have tried single quotes, double quotes, quotes around the whole thing, quotes only around the colon, backslash.

Also, I am not using the puppet module because I cannot become root on the other side, I only have sudo privs to the command … Suggesting I use the puppet modules is not an option for us, unfortunately.

Any suggestions on how to escape this colon? Is this an issue with the find function? I feel the answer will be something really obvious.

If I remove the “and puppet\_execute.stdout.find(“has failures: true”) \> -1” or remove the colon, the play runs just fine. It is this darn colon!!!

Here is the execute.yml from the role “puppet\_apply”

- name: “Executing puppet apply”  
become: no  
changed\_when: false  
ignore\_errors: yes  
shell: cd /var/tmp && sudo /usr/local/bin/puppet agent -t --no-noop | grep -v 'Loading facts in ’ | sed -r ‘s/\x1B[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g’  
args:  
executable: /bin/bash  
register: puppet\_execute  
when: puppet\_prompt == “GO”

- name: Verify if puppet was already running  
fail: msg=“PUPPET ALREADY RUNNING – ABORT”  
when: puppet\_prompt == “GO” and puppet\_execute.stdout.find(“Run of Puppet configuration client already in progress”) \> -1

- name: Verify if any errors detected  
fail: msg=“PUPPET ISSUES”  
when: puppet\_prompt == “GO” and puppet\_execute.stdout.find(“has failures: true”) \> -1

2016-09-22 11:13:09,179 p=26334 u=sysint | fatal: [hostA]: FAILED! =\> {“failed”: true, “reason”: “Syntax Error while loading YAML.\n\n\nThe error appears to have been in ‘/app/sysint/ansible/roles/puppet\_apply/tasks/execute.yml’: line 19, column 76, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n fail: msg="PUPPET ERRORS DETECTED"\n when: puppet\_prompt == "GO" and puppet\_execute.stdout.find("‘has failures: true’") \> -1\n ^ here\nWe could be wrong, but this one looks like it might be an issue with\nunbalanced quotes. If starting a value with a quote, make sure the\nline ends with the same set of quotes. For instance this arbitrary\nexample:\n\n foo: "bad" "wolf"\n\nCould be written as:\n\n foo: ‘"bad" "wolf"’\n”}

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [September 22, 2016, 6:59pm UTC](https://forum.ansible.com/t/yaml-and-colons-cannot-escape-quote-need-help/22621/2 "2016-09-22T18:59:10Z")

</div>

\<snip\>

> In this case, the error string I am looking for is "has failures: true"
> 
> The string I am looking for has a colon and I cannot for the life of me  
> escape it.
> 
> I have tried single quotes, double quotes, quotes around the whole thing,  
> quotes only around the colon, backslash.

Quotes around the whole when expression should work.

\<snip\>

> - name: Verify if any errors detected  
> &nbsp;&nbsp;fail: msg="PUPPET ISSUES"  
> &nbsp;&nbsp;when: puppet\_prompt == "GO" and puppet\_execute.stdout.find("has failures: true") \> -1

Have you tied this?

when: 'puppet\_prompt == "GO" and puppet\_execute.stdout.find("has failures: true") \> -1'
