How to check if a file exists in Ansible?

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

    A note on relative paths to complement the other answers.

    When doing infrastructure as code I'm usually using roles and tasks that accept relative paths, specially for files defined in those roles.

    Special variables like playbook_dir and role_path are very useful to create the absolute paths needed to test for existence.

提交回复
热议问题