Skip to content

Instantly share code, notes, and snippets.

@AlexMikhalev
Created May 6, 2020 09:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexMikhalev/14bc5e08a0f1205236f419540ccd5704 to your computer and use it in GitHub Desktop.
Save AlexMikhalev/14bc5e08a0f1205236f419540ccd5704 to your computer and use it in GitHub Desktop.
Create multiple folders using ansible without changing permissions
---
- name: "Creating multiple by checking folders"
hosts: your_host_name
tasks:
- block:
- name: "Checking folders"
stat:
path: "{{item}}"
register: folder_stats
with_items:
- ["/var/www/f1","/var/www/f2","/var/www/f3","/var/www/f4"]
- name: "Creating multiple folders without disturbing previous permissions"
file:
path: "{{item.item}}"
state: directory
mode: 0755
group: root
owner: root
when: item.stat.exists == false
with_items:
- "{{folder_stats.results}}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment