escaping - 如何在 Ansible lineinfile 模块中转义 '#' 注释字符?

标签 escaping yaml ansible

如何在 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/

相关文章:

python - 使用 ansible API 打印 hoSTList

swift - 在 Swift 字符串中包含 shell 转义字符

Ruby:如何用方括号 [ 和 ] 转义 url?

Azure Pipelines 矩阵变量

python - 使用 yaml 文件重命名 Pandas 数据框列

debugging - 如何调试 Ansible 包含和依赖项?

Swift - @escaping 和捕获列表说明

tsql - T-SQL 转义引号字符

yaml - CloudFormation YAML 状态机 : INVALID_JSON_DESCRIPTION for unrecognized token

ansible - 在 ansible 中,我可以为模块使用变量而不是使用模块名称吗?