# Output only changed list items

**URL:** <https://forum.ansible.com/t/output-only-changed-list-items/24749>\
**Category:** Ansible Project\
**Created:** [June 16, 2017, 7:25pm UTC](https://forum.ansible.com/t/output-only-changed-list-items/24749 "2017-06-16T19:25:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![B\_Holmes](https://avatars.discourse-cdn.com/v4/letter/b/a8b319/32.png) [@B\_Holmes](https://forum.ansible.com/u/B_Holmes)\
**Post date:** [June 16, 2017, 7:25pm UTC](https://forum.ansible.com/t/output-only-changed-list-items/24749/1 "2017-06-16T19:25:39Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [June 19, 2017, 11:27pm UTC](https://forum.ansible.com/t/output-only-changed-list-items/24749/2 "2017-06-19T23:27:37Z")

</div>

I believe you want this:

- name: Output username and password  
&nbsp;&nbsp;&nbsp;&nbsp;debug:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;msg: "User was created: {{ item.name }}"  
&nbsp;&nbsp;&nbsp;&nbsp;with\_items: '{{ user.results }}'  
&nbsp;&nbsp;&nbsp;&nbsp;when: item|changed
