如何在 Ansible 的 lineinfile 模块中转义字符?
这是我要在服务器上插入的行:EMAIL='hi@demo.com' # Server notification email address enter only 1 address
但是当我尝试以下操作时,由于 YAML 错误,Ansible 拒绝解析它:line="EMAIL='{{ email_address }}' # Server notification email address enter only 1 address"
我猜这是因为我有一个奇怪的双引号、单引号、等号和井号字符的组合。
最佳答案
问题确实是#
在你的字符串中 - 无论出于何种原因。
尽管您可以使用此技巧轻松防止解析错误:
line="EMAIL='{{ email_address }}' {{ '#' }} Server notification email address enter only 1 address"
关于escaping - 如何在 Ansible lineinfile 模块中转义 '#' 注释字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30146023/