How to check if a file exists in Ansible?

后端 未结 11 1828
旧巷少年郎
旧巷少年郎 2020-12-23 02:35

I have to check whether a file exists in /etc/. If the file exists then I have to skip the task. Here is the code I am using:

- name: checking th         


        
11条回答
  •  感情败类
    2020-12-23 03:03

    Discovered that calling stat is slow and collects a lot of info that is not required for file existence check.
    After spending some time searching for solution, i discovered following solution, which works much faster:

    - raw: test -e /path/to/something && echo true || echo false
      register: file_exists
    
    - debug: msg="Path exists"
      when: file_exists == true
    

提交回复
热议问题