How to create a directory using Ansible

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

    here is easier way.

    - name: create dir command: mkdir -p dir dir/a dir/b

    0 讨论(0)
  • 2020-12-22 17:24

    Additional for all answers here, there is lot of situations when you need to create more then one directory so it is a good idea to use loops instead creating separate task for each directory.

    - name: Creates directory
      file:
        path: "{{ item }}"
        state: directory
      with_items:
      - /srv/www
      - /dir/foo
      - /dir/bar
    
    0 讨论(0)
  • 2020-12-22 17:25

    You can use the statement

    - name: webfolder - Creates web folder
      file: path=/srv/www state=directory owner=www-data group=www-data mode=0775`
    
    0 讨论(0)
  • 2020-12-22 17:25

    You need to use file module for this case. Below playbook you can use for your reference.

        ---
         - hosts: <Your target host group>
           name: play1
           tasks: 
            - name: Create Directory
              files:
               path=/srv/www/
               owner=<Intended User>
               mode=<Intended permission, e.g.: 0750>
               state=directory 
    
    0 讨论(0)
提交回复
热议问题