Ansible - Create multiple folders if don't exist

后端 未结 3 897
无人共我
无人共我 2021-02-03 23:44

Goal:

  • Create multiple directories if they don\'t exist.
  • Don\'t change permissions of existing folder

Current playbook:

- name:         


        
3条回答
  •  广开言路
    2021-02-04 00:26

    Ansible - Creating multiple folders without changing permissions of previously existing.

    Working fine for me. Hope this works for you as well just 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
          loop:
          - "{{folder_stats.results}}"
    ...
    

提交回复
热议问题