# Looping over Subelements example incorrect?

**URL:** <https://forum.ansible.com/t/looping-over-subelements-example-incorrect/16224>\
**Category:** Ansible Project\
**Created:** [September 15, 2014, 1:07am UTC](https://forum.ansible.com/t/looping-over-subelements-example-incorrect/16224 "2014-09-15T01:07:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Patrick\_Ansible-ML](https://avatars.discourse-cdn.com/v4/letter/p/a88e57/32.png) [@Patrick\_Ansible-ML](https://forum.ansible.com/u/Patrick_Ansible-ML)\
**Post date:** [September 15, 2014, 1:07am UTC](https://forum.ansible.com/t/looping-over-subelements-example-incorrect/16224/1 "2014-09-15T01:07:49Z")

</div>

Hi,

Just tried out the authorize\_key example in the 'Looping over Subelements' section of the docs [1] and wonder if it's incorrect?

When I try the example it only saves the last key instead of all of them. Copy of example and output below.

I'm using Ansible 1.7.1.

Thanks,  
Patrick

[1] [http://docs.ansible.com/playbooks\_loops.html#looping-over-subelements](http://docs.ansible.com/playbooks_loops.html#looping-over-subelements)

vars:

users:  
&nbsp;&nbsp;&nbsp;- name: alice  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;authorized:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- roles/builder/files/alice/onekey.pub  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- roles/builder/files/alice/twokey.pub  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- roles/builder/files/bob/id\_rsa.pub

tasks:

- name: Add authorized\_keys  
&nbsp;&nbsp;&nbsp;authorized\_key:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;user: "{{ item.0.name }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;key: "{{ lookup('file', item.1) }}"  
&nbsp;&nbsp;&nbsp;with\_subelements:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- users  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- authorized

TASK: [builder | builder | Add authorized\_keys]

---

<div class="post-metadata">

**Author:** ![Patrick\_Ansible-ML](https://avatars.discourse-cdn.com/v4/letter/p/a88e57/32.png) [@Patrick\_Ansible-ML](https://forum.ansible.com/u/Patrick_Ansible-ML)\
**Post date:** [September 15, 2014, 1:35pm UTC](https://forum.ansible.com/t/looping-over-subelements-example-incorrect/16224/2 "2014-09-15T13:35:38Z")

</div>

Apologies for replying to myself. Figured it out and thought I'd share for the archives: the example is correct. Using the same key with a different comment and filename is not enough to count as unique. With separately generated keys the example works great.

HTH,  
Patrick
