# Looping over Subelements

**URL:** <https://forum.ansible.com/t/looping-over-subelements/19193>\
**Category:** Ansible Project\
**Created:** [September 5, 2015, 2:35pm UTC](https://forum.ansible.com/t/looping-over-subelements/19193 "2015-09-05T14:35:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sacha\_Vukovic1](https://avatars.discourse-cdn.com/v4/letter/s/a5b964/32.png) [@Sacha\_Vukovic1](https://forum.ansible.com/u/Sacha_Vukovic1)\
**Post date:** [September 5, 2015, 2:35pm UTC](https://forum.ansible.com/t/looping-over-subelements/19193/1 "2015-09-05T14:35:46Z")

</div>

Hello,

I try to understand how works looping overs subelements, after reading this [loops\_subelements](http://docs.ansible.com/ansible/playbooks_loops.html#looping-over-subelements) I had copy & past the example and he doesn’t work :

TASK: [dbtier | debug msg=“name={{ item.0.user }} password={{ item.0.mysql.password }} host={{ item.1 }} priv={{ item.0.mysql.privs | join(‘/’) }}”] \*\*\*  
fatal: [srv-lbn-tux5] =\> could not find ‘mysql.hosts’ key in iterated item ‘{‘authorized’: [’/tmp/alice/onekey.pub’, ‘/tmp/alice/twokey.pub’], ‘name’: ‘alice’, ‘mysql’: {‘password’: ‘mysql-password’, ‘hosts’: [‘%’, ‘127.0.0.1’, ‘::1’, ‘localhost’], ‘privs’: [‘_._:SELECT’, ‘DB1.\*:ALL’]}}’

FATAL: all hosts have already failed – aborting

my tasks:

- debug: msg=“name={{ item.0.user }} password={{ item.0.mysql.password }} host={{ item.1 }} priv={{ item.0.mysql.privs | join(‘/’) }}”  
with\_subelements:
- users1
- mysql.hosts  
tags: debug

vars\_file:  
users1:

- name: alice  
authorized:
- /tmp/alice/onekey.pub
- /tmp/alice/twokey.pub  
mysql:  
password: mysql-password  
hosts:
- “%”
- “127.0.0.1”
- “::1”
- “localhost”  
privs:
- “_._:SELECT”
- “DB1.\*:ALL”
- name: bob  
authorized:
- /tmp/bob/id\_rsa.pub  
mysql:  
password: other-mysql-password  
hosts:
- “db1”  
privs:
- “_._:SELECT”
- “DB2.\*:ALL”

Ansible version:1.9.2

Can you explain me why ?

---

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [September 6, 2015, 3:21pm UTC](https://forum.ansible.com/t/looping-over-subelements/19193/2 "2015-09-06T15:21:46Z")

</div>

​The extended feature where you can target a subkey, is a featur eonly  
available in the developmen version - the upcoming v 2.0.

(The docs online seem to nog show that I'm afraid)​

---

<div class="post-metadata">

**Author:** ![Sacha\_Vukovic1](https://avatars.discourse-cdn.com/v4/letter/s/a5b964/32.png) [@Sacha\_Vukovic1](https://forum.ansible.com/u/Sacha_Vukovic1)\
**Post date:** [September 6, 2015, 6:27pm UTC](https://forum.ansible.com/t/looping-over-subelements/19193/3 "2015-09-06T18:27:12Z")

</div>

Erf ☹ , are you sure of that ?
