# Complex dictionary access

**URL:** <https://forum.ansible.com/t/complex-dictionary-access/30190>\
**Category:** Ansible Project\
**Created:** [April 25, 2019, 6:36pm UTC](https://forum.ansible.com/t/complex-dictionary-access/30190 "2019-04-25T18:36:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mark.tovey](https://avatars.discourse-cdn.com/v4/letter/m/ce73a5/32.png) [@mark.tovey](https://forum.ansible.com/u/mark.tovey)\
**Post date:** [April 25, 2019, 6:36pm UTC](https://forum.ansible.com/t/complex-dictionary-access/30190/1 "2019-04-25T18:36:42Z")

</div>

I have a dictionary structure that looks like the following:

> 

> myservers:

> > DC1:

> > > CORE: 10.10.10.20

> > > DMZ: 10.10.20.20

> > DC2:

> > > CORE: 10.10.10.30.20

> > > DMZ: 10.10.10.40.20

> > DC3:

> > > CORE: 10.10.50.20

> > > DMZ: 10.10.60.20

> > DC4:

> > > CORE: 10.10.70.20

> > > DMZ: 10.10.80.20

And another dictionary that looks like the following:

> location:

> > address: 10.10.10.10

> > dc: DC1

> > net: 10.10.10.0

> > bits: 24

> > zone: CORE

I want to do something like the following:

> - debug:

> > msg: “myserver = myservers[‘{{location.dc}}’][‘{{location.zone}}’]”

and get back the message:

> myserver = 10.10.10.20

But instead, I get:

> myserver = myservers[‘DC1’][‘CORE’]

I want to see the value stored at myservers[‘DC1’][‘CORE’], not the string “myservers[‘DC1’][‘CORE’]”.

I have tried " {{ myservers[‘{{location.dc}}’]['{{location.zone}}] }}", but YAML does not allow nested braces, so that fails. And I have tried many other variations, but they all fail too. I am stymied. How do I extract the information I want?

---

<div class="post-metadata">

**Author:** ![user83](https://avatars.discourse-cdn.com/v4/letter/u/b38774/32.png) [@user83](https://forum.ansible.com/u/user83)\
**Post date:** [April 25, 2019, 6:49pm UTC](https://forum.ansible.com/t/complex-dictionary-access/30190/2 "2019-04-25T18:49:31Z")

</div>

Hello.  
Try use “{{myserver[location.dc][location.zone]}}”

пт, 26 апр. 2019 г., 1:36 ‘Mark Tovey’ via Ansible Project \<[ansible-project@googlegroups.com](mailto:ansible-project@googlegroups.com)\>:

---

<div class="post-metadata">

**Author:** ![mark.tovey](https://avatars.discourse-cdn.com/v4/letter/m/ce73a5/32.png) [@mark.tovey](https://forum.ansible.com/u/mark.tovey)\
**Post date:** [April 25, 2019, 7:36pm UTC](https://forum.ansible.com/t/complex-dictionary-access/30190/3 "2019-04-25T19:36:44Z")

</div>

I knew it was going to be simple, although I thought I tried that one too. But that got it.

Thanks!

> **(attachments)**
>
> ![image001.gif](https://us1.discourse-cdn.com/ansible/original/2X/b/b4bff17d9a47b579955542df88244e4ed45d94f4.gif)  
> ![image002.png](https://us1.discourse-cdn.com/ansible/original/2X/5/5b66cf09fa8b8d9e8a019dc18020d43a5cca4b68.png)
