问题原文
原帖链接 · stochastic · CC BY-SA 3.0
I am trying to use ansible to check that the output of a particular program is set to a certain value. That value includes a colon followed by a space, and this seems to register as a syntax error no matter how I quote it.
example:
---
- hosts: all
tasks:
- raw: echo "something: else"
register: progOutput
- debug:
msg: "something else happened!"
when: progOutput.stdout_lines[-1] != "something: else"
When I run this, I get an error on the first 'raw' command:
ERROR! Syntax Error while loading YAML.
The error appears to have been in '<snip>/test.yml': line 4, column 27, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
tasks:
- raw: echo "something: else"
^ here
(naturally, my actual use case involved a real program that had a colon in its output, not 'raw: echo'. This was nevertheless the error I saw.)
Clearly, quoting the string in question doesn't fix the problem. I also tried escaping the : with a backslash (\).
社区高分解答
原帖链接 · Abhijeet Kasurde · CC BY-SA 3.0
It is documented in Ansible's documentation about this.
You can escape colon like this -
- raw: echo "something {{':'}} else"
and output of this is like -
changed: [localhost] => {
"changed": true,
"rc": 0,
"stderr": "",
"stdout": "something : else\n",
"stdout_lines": [
"something : else"
]
}
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
