Skip to content

How to Create a Directory using Ansible

If you need to create a directory using Ansible, then you can do the following:

Create a Directory in Ansible

You will need the file module, then to create a directory you simply specify the option state=directory:

- name: Creates a directory file: path: /src/www state: directory
Code language: YAML (yaml)

Note that with state=directory, all the immediate subdirectories will be created if they don’t already exist.

Extending the file module

- name: Creates a directory file: path: /src/www state: directory owner: www-data group: www-data mode: 0775
Code language: YAML (yaml)

Create the Directories Recursively

- name: Creates directory file: path: /src/www state: directory owner: www-data group: www-data mode: 0775 recurse: yes
Code language: YAML (yaml)

This is similar to the recursive argument used with mkdir -p

See also  How to Determine if a Bash Variable is Empty
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x