# Using variable to access specific node in dict

**URL:** <https://forum.ansible.com/t/using-variable-to-access-specific-node-in-dict/17357>\
**Category:** Ansible Project\
**Created:** [January 22, 2015, 6:05pm UTC](https://forum.ansible.com/t/using-variable-to-access-specific-node-in-dict/17357 "2015-01-22T18:05:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cselden](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/cselden/32/4405_2.png) [@cselden](https://forum.ansible.com/u/cselden)\
**Post date:** [January 22, 2015, 6:05pm UTC](https://forum.ansible.com/t/using-variable-to-access-specific-node-in-dict/17357/1 "2015-01-22T18:05:20Z")

</div>

Greetings,

I’m trying to use a variable to determine which node in a dictionary to get information from. I will later want to use this for iterating over lists of variables so that I can use specific nodes in a dict without looping over all of them.

I have the following vars:  
myperson: bob  
people:  
alice:  
name: alice  
age: 30  
bob:  
name: bob  
age: 30

I using the following task to test the result:

- name: Debug out myperson’s name  
debug: msg=“name = {{people.{{myperson}}.name}}”

This returns the following error:  
template error while templating string: expected name or number

Note the only way that I have gotten this to evaluate correctly is if I use the following task where I only need one set of braces:

- name: Debug out myperson’s name  
debug: var=people.{{myperson}}.name

However, I cannot use this syntax in other cases (such as the shell or lineinfile modules). Is there some syntax for nesting variables in this way that I’m not aware of?

Thanks,  
Chip

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [January 22, 2015, 6:37pm UTC](https://forum.ansible.com/t/using-variable-to-access-specific-node-in-dict/17357/2 "2015-01-22T18:37:07Z")

</div>

Try:

{{people[myperson].name}}

---

<div class="post-metadata">

**Author:** ![cselden](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/cselden/32/4405_2.png) [@cselden](https://forum.ansible.com/u/cselden)\
**Post date:** [January 22, 2015, 6:57pm UTC](https://forum.ansible.com/t/using-variable-to-access-specific-node-in-dict/17357/3 "2015-01-22T18:57:47Z")

</div>

Matt,

Thanks, that’s a good thought, but it returned the same error.

---

<div class="post-metadata">

**Author:** ![cselden](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/cselden/32/4405_2.png) [@cselden](https://forum.ansible.com/u/cselden)\
**Post date:** [January 26, 2015, 10:05pm UTC](https://forum.ansible.com/t/using-variable-to-access-specific-node-in-dict/17357/4 "2015-01-26T22:05:16Z")

</div>

Matt,

I revisited this and I’m not sure what I did wrong before, but it worked! Thanks for the tip.
