我试图获得类似于本文的效果:https://gryzli.info/2017/12/21/ansible-debug-print-variables/
这意味着在我的情况下:
- name: Gather facts
vars:
msg: |
"{{ansible_distribution}}"
"{{ansible_distribution_major_version}}"
"{{ansible_distribution_release}}"
"{{ansible_distribution_version}}"
问题是如果没有引号,添加引号会引发错误。使用引号会引发相同的错误:
We could be wrong, but this one looks like it might be an issue with missing quotes. Always quote template expression brackets when theystart a value....
如何正确转义此多行字符串以便 Ansible 可以解析它?或者这种代码不再有效?
最佳答案
Q: "How do I correctly escape this multiline string so that Ansible can parse it?"
A:问题是块的缩进。引自 Example 8.3. Invalid Block Scalar Indentation Indicators
ERROR:
- A leading all-space line must not have too many spaces.
- A following text line must not be less indented.
- The text is less indented than the indicated level.
正确的语法是(带或不带引号)
vars:
msg: |
"{{ansible_distribution}}"
"{{ansible_distribution_major_version}}"
"{{ansible_distribution_release}}"
"{{ansible_distribution_version}}"
关于ansible - 多行模板 - Ansible 中的字符串转义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58889303/