# Help with access to all items in a dictionary

**URL:** <https://forum.ansible.com/t/help-with-access-to-all-items-in-a-dictionary/19594>\
**Category:** Ansible Project\
**Created:** [October 23, 2015, 11:08am UTC](https://forum.ansible.com/t/help-with-access-to-all-items-in-a-dictionary/19594 "2015-10-23T11:08:09Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Roman1](https://avatars.discourse-cdn.com/v4/letter/r/eada6e/32.png) [@Roman1](https://forum.ansible.com/u/Roman1)\
**Post date:** [October 23, 2015, 11:08am UTC](https://forum.ansible.com/t/help-with-access-to-all-items-in-a-dictionary/19594/1 "2015-10-23T11:08:09Z")

</div>

Hello,

I want to create MySQL users on several db server. Each of servers has several databases. Users can get access to databases from different hosts and with different rights. I’ve described variables in the dictionary which presented below.

Is it possible to get access to each items in the dictionary?

I’ve tried to do that via with\_subelements. But unfortunately it can operate only with two iterations. My trial presented under the dictionary.

Please, could you give me a piece of advice, how I can do it.

dbservers:  
server1:  
name: “server1”  
databases:  
server1db1:  
name: “server1db1”  
collation: “utf8\_general\_ci”  
encoding: “utf8”  
state: “present”  
server1\_db2:  
name: “server1db2”  
collation: “utf8\_general\_ci”  
encoding: “utf8”  
state: “present”  
users:  
server1user1:  
name: “server1user1”  
pass: “server1user1\_pass”  
state: “present”  
hosts:  
localhost:  
name: “localhost”  
append\_privs: “yes”  
privs: “_._:EVENT, PROCESS, REPLICATION CLIENT”  
server1user2:  
name: “server1user2”  
pass: “server1\_user2\_pass”  
state: “present”  
hosts:  
hostip1:  
name: “10.0.0.1”  
append\_privs: “yes”  
privs: “_._:PROCESS, SUPER”  
hostip2:  
name: “10.0.1.185”  
append\_privs: “yes”  
privs: “server1\_db2._:USAGE"  
server2:  
name: “server2”  
databases:  
server2db1:  
name: “server2db1”  
collation: “utf8\_general\_ci”  
encoding: “utf8”  
state: “present”  
server2\_db2:  
name: “server2db2”  
collation: “utf8\_general\_ci”  
encoding: “utf8”  
state: “present”  
server2\_db3:  
name: “server2db3”  
collation: “utf8\_general\_ci”  
encoding: “utf8”  
state: “present”  
users:  
server2user1:  
name: “server2user1”  
pass: “server2user1\_pass”  
state: “present”  
hosts:  
localhost:  
name: “localhost”  
append\_privs: “yes”  
privs: "_.\*:EVENT, PROCESS, REPLICATION CLIENT”  
server2user2:  
name: “server2user2”  
pass: “server2user2\_pass”  
state: “present”  
hosts:  
all:  
name: “%”  
append\_privs: “yes”  
privs:

- “server2\_db1.\*:USAGE”
- “server2\_db3.\*:ALL”

My trial:

- name: Ensure MySQL users are present.  
mysql\_user:  
name: “{{ item.1.name }}”  
password: “{{ item.1.pass|default ‘Pa$$word’ }}”  
state: “{{ item.1.state|default ‘yes’ }}”  
host: “{{ item.2.name|default “localhost” }}”  
priv: “{{ item.2.privs|default “_._:USAGE” }}”  
append\_privs: “{{ item.2.append\_privs|default “yes” }}”  
with\_subelements:
- dbservers
- users
- hosts  
when: (inventory\_hostname == “{{ item.0.name }}”)
