我正在尝试使用 ansible 来检查特定程序的输出是否设置为某个值。该值包括一个冒号,后跟一个空格,无论我如何引用它,这似乎都会注册为语法错误。
例子:
---
- hosts: all
tasks:
- raw: echo "something: else"
register: progOutput
- debug:
msg: "something else happened!"
when: progOutput.stdout_lines[-1] != "something: else"
Run Code Online (Sandbox Code Playgroud)
当我运行它时,第一个“原始”命令出现错误:
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
Run Code Online (Sandbox Code Playgroud)
(自然,我的实际用例涉及一个真实的程序,它的输出中有一个冒号,而不是 'raw: echo'。然而,这仍然是我看到的错误。)
显然,引用有问题的字符串并不能解决问题。我还尝试使用反斜杠 ( \
)转义 …