file module
The module that makes sure a file, directory or link exists or is absent, with the owner and permissions you ask for.
In more detail
With state set to directory it creates the directory if missing and reports ok if it is already there, which makes it the idempotent replacement for mkdir -p. Its mode argument sets permissions, and should be quoted, such as "0755", so YAML does not read it as a number.
Example
ansible all -m file -a "path=demo state=directory"Related terms
- idempotency — The property of an operation that gives the same result whether you run it once or many times, because a repeat run finds nothing left to do.
- file permissions — Rules on each file saying which user and group own it and who may read, write or run it.
- copy module — The module that puts a file on a host, either copied from the control node or written from content given in the task.
- mkdir — The shell command that makes a new directory; with -p it also makes missing parent directories and does not complain if the directory already exists.
Taught in
- What Configuration Management Is — Ansible Configuration Management at Scale
- Your First Ad Hoc Command — Ansible Configuration Management at Scale
- Writing Your First Playbook — Ansible Configuration Management at Scale
- SSH Keys And An Account For Ansible — RHCE in Ansible (EX294): Automate Red Hat Systems
- Anatomy Of A Playbook: Plays, Tasks And Modules — RHCE in Ansible (EX294): Automate Red Hat Systems
- Deploying Files: file, copy, lineinfile And blockinfile — RHCE in Ansible (EX294): Automate Red Hat Systems
- Conditionals: register, when, changed_when And failed_when — RHCE in Ansible (EX294): Automate Red Hat Systems
- Handlers And Failure: notify, block, rescue And always — RHCE in Ansible (EX294): Automate Red Hat Systems