How to create a directory using Ansible

后端 未结 22 1647
暗喜
暗喜 2020-12-22 16:44

How do you create a directory www at /srv on a Debian-based system using an Ansible playbook?

22条回答
  •  长情又很酷
    2020-12-22 17:09

    To check if directory exists and then run some task (e.g. create directory) use the following

    - name: Check if output directory exists
        stat:
        path: /path/to/output
        register: output_folder
    
    - name: Create output directory if not exists
        file:
        path: /path/to/output
        state: directory
        owner: user
        group: user
        mode: 0775
        when: output_folder.stat.exists == false
    

提交回复
热议问题