【问题标题】:Ansible lineinfile escape special charactersAnsible lineinfile 转义特殊字符
【发布时间】:2016-12-21 21:56:08
【问题描述】:

我正在尝试使用 ansible 替换远程文件中的一行。

这是一个php 文件,包含:

'cache' => true,

我尝试了很多不同的解决方案,但没有一个奏效。我觉得我离得太近了,但我做不到。请你帮助我好吗? 这就是我所做的:

lineinfile: "dest=/home/ubuntu/www/2.5.0/app/config/preprod/app.php regexp=^\'cache\'=> line=\'cache\' => {{ var }}"

var 为真或假,是通过命令行设置的参数。输出显示我添加了一行。但这不是我想要的。提前谢谢你。

【问题讨论】:

    标签: php regex yaml ansible ansible-playbook


    【解决方案1】:

    避免在复杂情况下使用param=value,改用dict风格,这样更容易阅读:

     - lineinfile:
         dest: "/home/ubuntu/www/2.5.0/app/config/preprod/app.php"
         regexp: "^'cache' =>"
         line: "'cache' => {{ var | string | lower }},"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-01
      • 2019-01-29
      • 2018-07-16
      • 1970-01-01
      相关资源
      最近更新 更多