I have a role, that has to create a list of directories. Which directories end up in the list, depends on several conditions that are evaluated at runtime.
When I use the file
module, like shown, this is very slow. Creating and even checking for the existence of every directory takes about half a second, which easily sums up to minutes in the scenarios I encounter.
Pipelining is enabled.
- name: Create directories
file:
path: "{{ item }}"
state: directory
with_items:
- "{{ dirs }}"
when:
- dirs is defined
A similar question has been asked here, however using synchronize
or unarchive
, as suggested there, seems very awkward for directories not known in advance, as the directory structure to be synchronized, first has to be created on the local host somewhere.
Are there other alternatives to solve this, I might have missed?
EDIT:
I am aware of shell
and command
and mkdir -p
happens to be idempotent. Still I would prefer a way, where ansible manages the state of the directories.