Ansible: Insert line if not exists

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

    This is the only way I was able to get this to work.

    - name: checking for host
      shell: cat /database.properties | grep couchbase.host | wc -l
      register: test_grep
    
    - debug: msg="{{test_grep.stdout}}"
    
    - name: adding license server
      lineinfile: dest=/database.properties line="couchbase.host=127.0.0.1"
      when: test_grep.stdout == "0"
    

提交回复
热议问题