user20
(Андрей Климентьев)
March 15, 2017, 6:33am
1
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
`
ZillaYT
(ZillaYT)
January 30, 2018, 7:16pm
2
I’m trying to do the same thing. What version of Ansible are you using? I use v2.4.2.0 and the acl module does NOT have a recursive parameter, but I see you use it?
I'm trying to do the same thing. What version of Ansible are you using? I
use v2.4.2.0 and the acl module does NOT have a recursive parameter, but I
see you use it?
Where to you get that from?
From the docs https://docs.ansible.com/ansible/latest/acl_module.html#options
recursive (added in 2.0) - Recursively sets the specified ACL (added in Ansible 2.0). Incompatible with state=query.
ZillaYT
(ZillaYT)
January 30, 2018, 7:25pm
4
I would suggest to use the official documentation and not some random site on the Internet.
ZillaYT
(ZillaYT)
January 30, 2018, 7:34pm
6
It looked official to me.
(Sorry to hijack the thread)
ZillaYT
(ZillaYT)
January 30, 2018, 8:26pm
7
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
`