Ansible - create multiple folders without changing the permissions of previously existing ones.
I work great. Hope this works for you, but just give it a try.
--- - 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}}" ...
source share