Only check whether a line present in a file (ansible)

后端 未结 8 2008
粉色の甜心
粉色の甜心 2020-12-01 02:36

In ansible, I need to check whether a particular line present in a file or not. Basically, I need to convert the following command to an ansible task. My goal is to only che

8条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-01 03:14

    - name: Check whether /tmp/my.conf contains "127.0.0.1"
      command: grep -Fxq "127.0.0.1" /tmp/my.conf
      register: checkmyconf
      check_mode: no
      ignore_errors: yes
      changed_when: no
    
    - name: Greet the world if /tmp/my.conf contains "127.0.0.1"
      debug: msg="Hello, world!"
      when: checkmyconf.rc == 0
    

    Update 2017-08-28: Older Ansible versions need to use always_run: yes instead of check_mode: no.

提交回复
热议问题