I`m setting new ansible role to create new IPA users and groups. User creation works fine, but Im struggling with groups.
This is snippet from my vars and playbook. Ansible version is 2.4.2.0
vars:
ipagroups:
ansible_group_test1:
group: ansible_group_test1
users:
- ansible_test1
- ansible_test2
ansible_group_test2:
group: ansible_group_test2
users:
- ansible_test1
- ansible_test2
ansible_group_test3:
group: ansible_group_test3
users:
- ansible_test1
- ansible_test2
task:
- name: adding ipa groups and users
ipa_group:
name: "{{item.value.group}}"
state: present
user: "{{item.value.users}}"
ipa_host: ipa.example.com
ipa_user: admin
ipa_pass: xxx
with_dict: "{{ ipagroups }}"
when: item.key == "ipagroups.keys()"
I expected the groups to be created, but I get: "skip_reason": "Conditional result was False"
Note: If I try it with e.g. when: item.key == 'ansible_group_test1' it works correctly
I think you need when: item.key in ipagroups.keys()
I put your vars, verbatim, in group_vars/all, and have an empty inventory file. This playbook:
- hosts: localhost
connection: local
tasks:
- name: Show vars
debug:
var: item.value.group
when: item.key in ipagroups.keys()
with_dict: "{{ ipagroups }}"
Gives me:
TASK [Show vars] ***************************************
ok: [localhost] => (item=None) => {
"item.value.group": "ansible_group_test2"
}
ok: [localhost] => (item=None) => {
"item.value.group": "ansible_group_test3"
}
ok: [localhost] => (item=None) => {
"item.value.group": "ansible_group_test1"
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With