My vars.yml file is:
linux_users:
- username: testuser1
state: present
- username: testuser2
state: present
If I add another user:
linux_users:
- username: testuser1
state: present
- username: testuser2
state: present
- username: testuser3
state: present
how can I output only the username of the third user who was 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
when: item.state != 'absent'
with_items: '{{ linux_users }}'
- name: Output username and password
debug:
msg: "User was created: {{ item }}"
with_items: '{{ user.results[2].name }}'
when: user.changed
{{ user.results[2].name }} outputs what I need, but I won't know which user
will be created when I run the script. Is there any way to register the
list index integer of the user 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/10611f5b-982b-4449-b9b9-8aba64fb7575%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.