# concatenating variables to get nested dictionary items

**URL:** <https://forum.ansible.com/t/concatenating-variables-to-get-nested-dictionary-items/20139>\
**Category:** Ansible Developer\
**Created:** [January 7, 2016, 3:34pm UTC](https://forum.ansible.com/t/concatenating-variables-to-get-nested-dictionary-items/20139 "2016-01-07T15:34:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Arthur\_Reyes](https://avatars.discourse-cdn.com/v4/letter/a/90ced4/32.png) [@Arthur\_Reyes](https://forum.ansible.com/u/Arthur_Reyes)\
**Post date:** [January 7, 2016, 3:34pm UTC](https://forum.ansible.com/t/concatenating-variables-to-get-nested-dictionary-items/20139/1 "2016-01-07T15:34:45Z")

</div>

I’m hung up on syntax at the moment and was wondering if someone could point out what I’m doing incorrectly.

I’m trying to create an ntp.j2 template and populate peers based on the value of ansible\_local.datacenter. This is a sanitized example:

My dictionary:

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [January 7, 2016, 3:43pm UTC](https://forum.ansible.com/t/concatenating-variables-to-get-nested-dictionary-items/20139/2 "2016-01-07T15:43:41Z")

</div>

msg={{ ntp[ansible\_locall.datacenter]['peer1'] }}

[ntp] is a list containing ntp dictionary, that list does not have a  
chicago key (lists don't have keys, just ordinals).

---

<div class="post-metadata">

**Author:** ![Arthur\_Reyes](https://avatars.discourse-cdn.com/v4/letter/a/90ced4/32.png) [@Arthur\_Reyes](https://forum.ansible.com/u/Arthur_Reyes)\
**Post date:** [January 7, 2016, 4:10pm UTC](https://forum.ansible.com/t/concatenating-variables-to-get-nested-dictionary-items/20139/3 "2016-01-07T16:10:29Z")

</div>

Your answer is so obvious now … thank you for your quick reply.
