Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a directory using Ansible

How do you create a directory www at /srv on a Debian-based system using an Ansible playbook?

like image 835
Gaurav Agarwal Avatar asked Apr 03 '14 17:04

Gaurav Agarwal


People also ask

How do I make an Ansible folder?

To create a directory using the file module, you need to set two parameters. Path(alias – name, dest) – This is the absolute path of the directory. State – You should give this as 'directory. ' By default, the value is 'file.

Which module will you use to create a directory in Ansible?

You can use the file module. To create a directory, you need to specify the option state=directory.

How do you create directory if not exist in Ansible?

If file , the file will NOT be created if it does not exist, see the [copy] or [template] module if you want that behavior. If link , the symbolic link will be created or changed. Use hard for hardlinks. If absent , directories will be recursively deleted, and files or symlinks will be unlinked.


1 Answers

You want the file module. To create a directory, you need to specify the option state=directory :

- name: Creates directory   file:     path: /src/www     state: directory 

You can see other options at https://docs.ansible.com/ansible/latest/collections/ansible/builtin/file_module.html

like image 64
leucos Avatar answered Oct 03 '22 19:10

leucos