I'm a total Ansible and Python beginner. I have a list:
my_items:
- name: item1
unix_user: unixuser1
homedir: /home/unixuser2
- name: item2
unix_user: unixuser2
homedir: /home/unixuser2
I would like to create a pureftpd virtual user for each of "my_items".
The role awaits a variable like this:
my_items:
- name: item1
unix_user: unixuser1
homedir: /home/unixuser2
uid: 1001
guid: 1001
- name: item2
unix_user: unixuser2
homedir: /home/unixuser2
uid: 1002
guid: 1002
I know how to retrieve the uid/guid (using getent). I can manage to add the new keys/values to each item:
- name: "Populate UID and GID in my_items"
set_fact:
item: "{{ item | combine( { 'uid': getent_passwd[item.unix_user][1], 'gid': getent_passwd[item.unix_user][2] }) }}"
with_items: "{{ my_items }}"
But of course, the "global" my_items variable isn't updated.
I tried to create a new "dictionnary" but I can't get my head around so many concepts at the same time.
Any help would be appreciated!