Ansible: Insert line if not exists

后端 未结 10 1318
庸人自扰
庸人自扰 2020-12-25 11:27

I\'m trying insert a line in a property file using ansible. I want to add some property if it does not exist, but not replace it if such property already exists in the file.

10条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-25 11:56

    We have tried the below and it worked well. our scenario need to entry "compress" in syslog file if it does not exist.

    - name: Checking compress entry present if not add entry   
      lineinfile:
        path: /etc/logrotate.d/syslog
        regexp: "    compress"
        state: present
        insertafter: "    missingok"
        line: "    compress"
    

提交回复
热议问题