# Using variables as dictionary keys

**URL:** <https://forum.ansible.com/t/using-variables-as-dictionary-keys/19270>\
**Category:** Ansible Project\
**Created:** [September 15, 2015, 4:57pm UTC](https://forum.ansible.com/t/using-variables-as-dictionary-keys/19270 "2015-09-15T16:57:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Patrick\_McMahon](https://avatars.discourse-cdn.com/v4/letter/p/2acd7d/32.png) [@Patrick\_McMahon](https://forum.ansible.com/u/Patrick_McMahon)\
**Post date:** [September 15, 2015, 4:57pm UTC](https://forum.ansible.com/t/using-variables-as-dictionary-keys/19270/1 "2015-09-15T16:57:57Z")

</div>

Hi,

Is something like this possible when defining a dictionary in defaults/main.yml:

`  
agent\_instances:  
“{{ [ansible\_fqdn] }}”:  
port: 5912  
“{{ [ansible\_fqdn]-2 }}”:  
port: 5913

`

I want to then call `agent_instances.keys() | join (",") `in a jinja2 template.

Thanks in Advance!

Paddy

---

<div class="post-metadata">

**Author:** ![Dan\_Stillman](https://avatars.discourse-cdn.com/v4/letter/d/ecb155/32.png) [@Dan\_Stillman](https://forum.ansible.com/u/Dan_Stillman)\
**Post date:** [September 15, 2015, 7:24pm UTC](https://forum.ansible.com/t/using-variables-as-dictionary-keys/19270/2 "2015-09-15T19:24:27Z")

</div>

Similar request here:

---

<div class="post-metadata">

**Author:** ![Patrick\_McMahon](https://avatars.discourse-cdn.com/v4/letter/p/2acd7d/32.png) [@Patrick\_McMahon](https://forum.ansible.com/u/Patrick_McMahon)\
**Post date:** [September 15, 2015, 8:08pm UTC](https://forum.ansible.com/t/using-variables-as-dictionary-keys/19270/3 "2015-09-15T20:08:35Z")

</div>

Ahh, I’ll have to think of another way to do it then. Thanks Dan!

Paddy
