You can try the loop_control and loop_var technique discussed 
in 
http://docs.ansible.com/ansible/latest/playbooks_loops.html#loops-and-includes-in-2-0

So in one file you may have

vars:
    deploy_username: deploy-a
    directories:
    - path: /var/www
      owner: www-data
      group: www-data
      permissions: "0770"
      recursive_perms: yes
      acl:
      - etype: user
        permissions: rwX
        entity: www-data
      - etype: user
        permissions: rwX
        entity: "{{ deploy_username }}"

  - incolude_tasks: set-acl.yml
    with_items:
    - yes
    - no
    loop_control:
      loop_var: default_bool

The, in set-acl.yml you have your code:

  - name: Set ACL on directories
    acl:
      path: "{{ item.0.path }}"
      entity: "{{ item.1.entity }}"
      etype: "{{ item.1.etype }}"
      permissions: "{{ item.1.permissions }}"
      state: present
      default: "{{ default_bool }}"
      recursive: "{{ item.0.recursive_perms }}"
    with_subelements:
    - "{{ directories }}"
    - acl


On Wednesday, March 15, 2017 at 9:50:31 AM UTC-4, Андрей Климентьев wrote:
>
> Hi, everyone.
>
> Would it be possible to somehow merge those two tasks in one? As you can 
> see, the only difference is in *default: [yes|no] *key.
> I have to install both default and non-default ACL on a filesystem object, 
> but I am am stuck with (perceived) deficiencies of Ansible loops. Can I 
> somehow alternate between those two boolean values, whilst also being able 
> to loop *with_subelements*?
>
>   vars:
>     deploy_username: deploy-a
>     directories:
>     - path: /var/www
>       owner: www-data
>       group: www-data
>       permissions: "0770"
>       recursive_perms: yes
>       acl:
>       - etype: user
>         permissions: rwX
>         entity: www-data
>       - etype: user
>         permissions: rwX
>         entity: "{{ deploy_username }}"
>
>   - name: Set ACL on directories
>     acl:
>       path: "{{ item.0.path }}"
>       entity: "{{ item.1.entity }}"
>       etype: "{{ item.1.etype }}"
>       permissions: "{{ item.1.permissions }}"
>       state: present
>       default: no
>       recursive: "{{ item.0.recursive_perms }}"
>     with_subelements:
>     - "{{ directories }}"
>     - acl
>
>
>   - name: Set default ACL on directories
>     acl:
>       path: "{{ item.0.path }}"
>       entity: "{{ item.1.entity }}"
>       etype: "{{ item.1.etype }}"
>       permissions: "{{ item.1.permissions }}"
>       state: present
>       default: yes
>       recursive: "{{ item.0.recursive_perms }}"
>     with_subelements:
>     - "{{ directories }}"
>     - acl
>
>
>
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/ed095286-44b3-4a94-9880-ce6c28515278%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to