How to check if a file exists in Ansible?

后端 未结 11 1878
旧巷少年郎
旧巷少年郎 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:19

    If you just want to make sure a certain file exists (f.ex. because it shoud be created in a different way than via ansible) and fail if it doesn't, then you can do this:

    - name: sanity check that /some/path/file exists
      command: stat /some/path/file
      check_mode: no # always run
      changed_when: false # doesn't change anything
    

提交回复
热议问题