How to create a directory using Ansible

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

    If you want to create directory in windows:

    • name: Create directory structure
      win_file:
      path: C:\Temp\folder\subfolder>
      state: directory

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

    you can create using:

    Latest version 2<

    - name: Create Folder
      file: 
        path: /srv/www/
        owner: user 
        group: user 
        mode: 0755 
        state: directory
    

    Older version

    - name: Create Folder
      file: 
       path=/srv/www/
       owner=user 
       group=user 
       mode=0755 
       state=directory
    

    Refer - http://docs.ansible.com/ansible/file_module.html

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

    You can create a directory. using

    # create a directory if it doesn't exist
    - file: path=/src/www state=directory mode=0755
    

    You can also consult http://docs.ansible.com/ansible/file_module.html for further details regaridng directory and file system.

    0 讨论(0)
  • 2020-12-22 17:18
    - file:
        path: /etc/some_directory
        state: directory
        mode: 0755
        owner: someone
        group: somegroup
    

    That's the way you can actually also set the permissions, the owner and the group. The last three parameters are not obligatory.

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

    Easiest way to make a directory in Ansible.

    • name: Create your_directory if it doesn't exist. file: path: /etc/your_directory

    OR

    You want to give sudo privileges to that directory.

    • name: Create your_directory if it doesn't exist. file: path: /etc/your_directory mode: '777'
    0 讨论(0)
  • 2020-12-22 17:21

    We have modules available to create directory , file in ansible

    Example

    - name: Creates directory
      file:
        path: /src/www
        state: directory
    
    0 讨论(0)
提交回复
热议问题