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