I have a vars.yml with a list of users:
linux_users:
- username: testuser1
state: present
- username: testuser2
state: present
If I create them, then add a third:
linux_users:
- username: testuser1
state: present
- username: testuser2
state: present
- username: testuser3
state: present
how can I output the username of the third user only (the one that is
created)? My task file is:
- hosts: 127.0.0.1
become: True
vars_files:
- vars.yml
- name: Create user
user:
name: "{{ item.username }}"
state: '{{ item.state }}'
register: user
with_items: '{{ linux_users }}'
when: item.state != 'absent'
- name: Output username
debug:
msg: "User was created: {{ item }}"
with_items: '{{ user.results[2].name }}'
when: user.changed
{{ user.results[2].name }} outputs what I need, but obviously I won't know
which user will be created, so this needs to be dynamic. Is there some way
to register an index integer of the user in the list that was created?
--
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/5a6c4b72-1c62-42d8-baf3-2a7cbb002883%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.