# How to combine a dict list and an items list and read the item.key from the dict list

**URL:** <https://forum.ansible.com/t/how-to-combine-a-dict-list-and-an-items-list-and-read-the-item-key-from-the-dict-list/18429>\
**Category:** Ansible Project\
**Created:** [June 8, 2015, 3:07pm UTC](https://forum.ansible.com/t/how-to-combine-a-dict-list-and-an-items-list-and-read-the-item-key-from-the-dict-list/18429 "2015-06-08T15:07:32Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Esteban\_Freire](https://avatars.discourse-cdn.com/v4/letter/e/d26b3c/32.png) [@Esteban\_Freire](https://forum.ansible.com/u/Esteban_Freire)\
**Post date:** [June 8, 2015, 3:07pm UTC](https://forum.ansible.com/t/how-to-combine-a-dict-list-and-an-items-list-and-read-the-item-key-from-the-dict-list/18429/1 "2015-06-08T15:07:32Z")

</div>

Hello all,

I have the following file in vars:

groups\_account:  
project-institute:  
status: create  
create\_group\_admin: create  
group\_admin\_user: test3  
group\_admin\_Name: “Pepito”  
group\_admin\_fullName: ‘GROUP\_ADMIN\_USER=“Pepito de los palotes”’  
group\_admin\_type\_authentication: core  
group\_admin\_default\_view: ‘DEFAULT\_VIEW=“cloud”’  
group\_admin\_mail: ‘Email=“algo@algo”’  
group\_admin\_telf: ‘Telf=“6123456789”’  
group\_admin\_role: ‘role=“admin”’  
group\_admin\_user\_info: ‘user\_info=“researcher”’  
group\_admin\_start\_date: ‘start\_date=“2015/12/13”’  
group\_admin\_end\_date: ‘end\_date=“2016/12/13”’  
group\_admins\_list:   
start\_date\_project: ‘start\_date\_project=“2015/12/13”’  
end\_date\_project: ‘end\_date\_project=“2016/12/13”’  
group\_admins\_project: ‘GroupAdmins\_for\_this\_project=“esteban, jose, pepe, ramon”’  
GROUP\_CPU\_QUOTA: 5000  
GROUP\_IMAGES\_SIZE\_QUOTA: 50000  
GROUP\_DB\_SIZE\_QUOTA: 100000  
network:  
project-institute2:  
status: create  
create\_group\_admin: nocreate  
group\_admin\_user:  
group\_admin\_Name: “PepitoIII”  
group\_admin\_fullName: ‘GROUP\_ADMIN\_USER=“Pepito de los palotes”’  
group\_admin\_type\_authentication: core  
group\_admin\_default\_view: ‘DEFAULT\_VIEW=“cloud”’  
group\_admin\_mail: ‘Email=“algo2@algo”’  
group\_admin\_telf: ‘Telf=“6123456789”’  
group\_admin\_role: ‘role=“admin”’  
group\_admin\_user\_info: ‘user\_info=“researcher”’  
group\_admin\_start\_date: ‘start\_date=“2015/12/13”’  
group\_admin\_end\_date: ‘end\_date=“2016/12/13”’  
group\_admins\_list:

- test1  
start\_date\_project: ‘start\_date\_project=“2015/12/13”’  
end\_date\_project: ‘end\_date\_project=“2016/12/13”’  
group\_admins\_project: ‘GroupAdmins\_for\_this\_project=“esteban, jose, pepe, ramon”’  
GROUP\_CPU\_QUOTA: 5000  
GROUP\_IMAGES\_SIZE\_QUOTA: 50000  
GROUP\_DB\_SIZE\_QUOTA: 100000  
network:

Ant the following task:

- name: Adding the group as secondary group to the groupadmins list  
sudo: True  
sudo\_user: oneadmin  
shell: check\_if\_user\_exist=`oneuser show {{ item.1 }} > /dev/null 2>&1`;if [$? == 0];then oneuser addgroup {{ item.1 }} {{ item.key }};fi  
with\_subelements:
- groups\_account
- group\_admins\_list  
when: (item.0.status == “create” and item.1 != “”)  
tags:
- create\_group

But I get the following issue:

TASK: [testing | Adding the group as secondary group to the groupadmins list] \*\*\*  
 ESTABLISH CONNECTION FOR USER: root  
fatal: [m-opennebula4] =\> One or more undefined variables: ‘list object’ has no attribute ‘key’

It seems that the key (in this case project-institute\*) is missing in this case and I don’t know how to read it 😕 … Does anyone know how could I read this value combining both lists?

Thanks in advance,  
Esteban

PS: … Sorry for the bad explanation, I am really tired right now 😕
