# List and Dict combined

**URL:** <https://forum.ansible.com/t/list-and-dict-combined/18679>\
**Category:** Ansible Project\
**Created:** [July 5, 2015, 8:10am UTC](https://forum.ansible.com/t/list-and-dict-combined/18679 "2015-07-05T08:10:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vishal\_Chainani](https://avatars.discourse-cdn.com/v4/letter/v/b9e5f3/32.png) [@Vishal\_Chainani](https://forum.ansible.com/u/Vishal_Chainani)\
**Post date:** [July 5, 2015, 8:10am UTC](https://forum.ansible.com/t/list-and-dict-combined/18679/1 "2015-07-05T08:10:00Z")

</div>

Hi,

Can a list have a combination of dict and lists? Below is my data and jinja2 template, while running the play book get an error.

snmp:  
location: xyz  
contact: admin

- community:  
name: public  
access: read-only  
clients:
- hosts: 8.8.8.8
- hosts: 10.10.10.10
- community:  
name: private  
access: read-write  
clients:
- hosts: 3.3.3.3
- hosts: 4.4.4.4

snmp {  
location “{{ snmp.location }}”“;  
contact “{{ snmp.contact }}”;”  
{% for snmp in snmp %}  
community {{ snmp.community.name }} {  
authorization {{ snmp.community.access }};  
clients {  
{% for client in snmp.community.clients %}  
{{ client.hosts }};  
{% endfor %}  
}  
}  
{% endfor %}  
}

(ansible)Vishals-MBP:ansible vishalc$ ansible-playbook main.yml  
ERROR: Syntax Error while loading YAML script, /etc/ansible/group\_vars/lab.yml  
Note: The error may actually appear before this position: line 27, column 5

contact: admin

- community:  
^

Vishal

---

<div class="post-metadata">

**Author:** ![jang](https://avatars.discourse-cdn.com/v4/letter/j/ecb155/32.png) [@jang](https://forum.ansible.com/u/jang)\
**Post date:** [July 5, 2015, 11:40am UTC](https://forum.ansible.com/t/list-and-dict-combined/18679/2 "2015-07-05T11:40:13Z")

</div>

Not quite, but you can have a dictionary member whose value is a list:

snmp:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;location: xyz  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;contact: admin  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;community:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- name: public  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;access: read-only  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;clients:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- hosts: 8.8.8.8  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- hosts: 10.10.10.10  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- name: private  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;access: read-write  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;clients:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- hosts: 3.3.3.3  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- hosts: 4.4.4.4

And here, each element of the 'community' list is a dict.

---

<div class="post-metadata">

**Author:** ![Vishal\_Chainani](https://avatars.discourse-cdn.com/v4/letter/v/b9e5f3/32.png) [@Vishal\_Chainani](https://forum.ansible.com/u/Vishal_Chainani)\
**Post date:** [July 5, 2015, 1:31pm UTC](https://forum.ansible.com/t/list-and-dict-combined/18679/3 "2015-07-05T13:31:09Z")

</div>

That works, thanks!
