【问题标题】:Ansible uncomment line and change string valueAnsible 取消注释行并更改字符串值
【发布时间】:2018-02-03 17:14:16
【问题描述】:

我在配置文件中有一行如下:

# value = False

我知道您可以使用 lineinfile 删除“#”,如下所示:

- name: Uncomment parameters
  lineinfile:
    dest: app.conf
    regexp: (?i)^\s*#\s*({{ item }}.*)
    line: \1
    backrefs: yes
  with_items:
    - value

我想知道是否有办法在同一个任务中也将“假”更改为“真”,还是需要另一个任务? (最有可能使用替换?)

【问题讨论】:

    标签: ansible


    【解决方案1】:

    当然,除非你想添加一些其他逻辑?

    - name: Uncomment parameters
      lineinfile:
        dest: app.conf
        regexp: (?i)^\s*#\s*{{ item }}.*
        line: "{{ item }} = True"
        backrefs: yes
      with_items:
      - value
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-04
      • 2014-09-13
      • 1970-01-01
      • 2021-07-26
      相关资源
      最近更新 更多