How to create a directory using Ansible

后端 未结 22 1660
暗喜
暗喜 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:10

    You can even extend the file module and even set the owner,group & permission through it. (Ref: Ansible file documentation)

    - name: Creates directory
      file:
        path: /src/www
        state: directory
        owner: www-data
        group: www-data
        mode: 0775
    

    Even, you can create the directories recursively:

    - name: Creates directory
      file:
        path: /src/www
        state: directory
        owner: www-data
        group: www-data
        mode: 0775
        recurse: yes
    

    This way, it will create both directories, if they didn't exist.

提交回复
热议问题