Ansible: Insert line if not exists

后端 未结 10 1308
庸人自扰
庸人自扰 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:38

    - name: add couchbase.host to properties, works like add or replace
      lineinfile:
        path: /database.properties
        regexp: '^couchbase.host=(?!(127.0.0.1))\b'
        line: 'couchbase.host=127.0.0.1'
    

    This code will replace any line ^couchbase.host=* except couchbase.host=127.0.0.1 or will add new line if it does not exist

提交回复
热议问题