# dictionary subset based on inventory?

**URL:** <https://forum.ansible.com/t/dictionary-subset-based-on-inventory/19996>\
**Category:** Ansible Project\
**Created:** [December 13, 2015, 2:26am UTC](https://forum.ansible.com/t/dictionary-subset-based-on-inventory/19996 "2015-12-13T02:26:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![pixel\_fairy](https://avatars.discourse-cdn.com/v4/letter/p/6f9a4e/32.png) [@pixel\_fairy](https://forum.ansible.com/u/pixel_fairy)\
**Post date:** [December 13, 2015, 2:26am UTC](https://forum.ansible.com/t/dictionary-subset-based-on-inventory/19996/1 "2015-12-13T02:26:18Z")

</div>

have a little lxc playbook making reverse proxies from one container to the others. it reads from a dictionary of container definitions, and i only want it to proxy the containers acting as web servers, which are in the group “web” in the inventory. how can i do this? the reverse proxy runs nginx and the host forwards port 80 to it.

heres the containers file,

`  
containers:  
reverseproxy:  
hostname: reverseproxy.lan  
address: 192.168.114.10  
forwards:

- { transport: tcp, host: 80, container: 80 }  
web1:  
hostname: web1.lan  
address: 192.168.114.11  
web2:  
hostname: web2.lan  
address: 192.168.114.12

`

heres the inventory

`  
[lxc]  
lxctest

[containers]  
reverseproxy ansible\_ssh\_host=192.168.114.10  
web1 ansible\_ssh\_host=192.168.114.11  
web2 ansible\_ssh\_host=192.168.114.12

[web]  
web1  
web2

`

and this calls the include that makes the pair of includes from the reverseproxy playbook

`

- include: make\_reverseproxy.yml  
vars:  
hostname: “{{ item.value.hostname }}”  
address: “{{ item.value.address }}”  
with\_dict: “{{ containers }}”  
`

item.key is also the ansible hostname, so maybe some kind of “when item.key in group web?”

i realize i could just make a list, but i hate repeating.

---

<div class="post-metadata">

**Author:** ![pixel\_fairy](https://avatars.discourse-cdn.com/v4/letter/p/6f9a4e/32.png) [@pixel\_fairy](https://forum.ansible.com/u/pixel_fairy)\
**Post date:** [December 13, 2015, 8:08pm UTC](https://forum.ansible.com/t/dictionary-subset-based-on-inventory/19996/2 "2015-12-13T20:08:20Z")

</div>

theres a globally available ‘groups’ so, as usual, its easy once you know it.

`

- include: make\_reverseproxy.yml  
vars:  
hostname: “{{ item.value.hostname }}”  
address: “{{ item.value.address }}”  
with\_dict: “{{ containers }}”  
when: item.key in groups[‘web’]

`
