How to create directory using Ansible

We can use file module to create folders using Ansible. In-order to create directory, we need to specify the option state=directory in the playbook.

Sample yaml snippet is given below.

- name: create directory
    path: full-path-to-sample_directory
    state: directory
    mode: "u=rw,g=wx,o=rwx"

If the directory already exists, Ansible will do nothing.

Here we need to replace full-path-to-sample_directory with corresponding path. Also note that the mode option will set the permissions over the directory. This can be changed to the requirements accordingly.

That's all…

Leave a Reply

Your email address will not be published. Required fields are marked *