Ansible - Create multiple folders if don't exist

后端 未结 3 890
无人共我
无人共我 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:11

    Starting from Ansible 2.5, loop should be used to iterate over a list, see https://docs.ansible.com/ansible/latest/user_guide/playbooks_loops.html#standard-loops

    As the Ansible file module is idempotent, you do not have to check if the folders already exist.

    For example:

    - name: create backup directories
      file:
        path: "{{ item }}"
        state: directory
        owner: backup
        group: backup
        mode: 0775
      loop:
        - /backupdisk/certificates
        - /backupdisk/mysql
        - /backupdisk/wordpress
    

提交回复
热议问题