How do you create a directory www
at /srv
on a Debian-based system using an Ansible playbook?
here is easier way.
- name: create dir
command: mkdir -p dir dir/a dir/b
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
You can use the statement
- name: webfolder - Creates web folder
file: path=/srv/www state=directory owner=www-data group=www-data mode=0775`
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