# Programmatic variable name access

**URL:** <https://forum.ansible.com/t/programmatic-variable-name-access/14462>\
**Category:** Ansible Project\
**Tags:** ubuntu\
**Created:** [January 30, 2014, 4:47pm UTC](https://forum.ansible.com/t/programmatic-variable-name-access/14462 "2014-01-30T16:47:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Juan\_Uys](https://avatars.discourse-cdn.com/v4/letter/j/9de053/32.png) [@Juan\_Uys](https://forum.ansible.com/u/Juan_Uys)\
**Post date:** [January 30, 2014, 4:47pm UTC](https://forum.ansible.com/t/programmatic-variable-name-access/14462/1 "2014-01-30T16:47:45Z")

</div>

Hello,

I’ve search here for “programmatic” and had a look at [http://docs.ansible.com/faq.html#how-do-i-access-a-variable-name-programatically](http://docs.ansible.com/faq.html#how-do-i-access-a-variable-name-programatically) but remain stumped.

I’ve got these group\_vars/all.yml:

applist: [boldface, taximeter]

> appconf:  
> boldface:  
> repo: [https://github.com/opyate/twitter-word-source](https://github.com/opyate/twitter-word-source)  
> install\_dir: “/opt/apps/boldface”  
> description: “Twitter Word Source API”  
> http\_port: 3000  
> https\_port: 4440  
> taximeter:  
> repo: [https://github.com/opyate/taximeter](https://github.com/opyate/taximeter)  
> install\_dir: “/opt/apps/taximeter”  
> description: “Taxi cab fare API as per TFL guidelines”  
> http\_port: 3001  
> https\_port: 4441

I’ve got this task (and many others for these similar apps):

> - name: API | Create app dir  
> file: dest={{appconf[$item][‘install\_dir’]}} owner=$ansible\_ssh\_user group=admin mode=755 state=directory  
> sudo: yes  
> tags: api  
> with\_items: “{{applist}}”

I expect it to create /opt/apps/boldface and /opt/apps/taximeter

However, I end up with stuff like this (after trying varying combinations of the ‘dest’ parameter in the task):

> r00t@vagrant-ubuntu-saucy-64:~$ ls /home/r00t/\*  
> /home/r00t/{{appconf[+boldface][install\_dir]}}:
> 
> /home/r00t/{{appconf[boldface][‘install\_dir’]}}:
> 
> /home/r00t/{{appconf[boldface][install\_dir]}}:
> 
> /home/r00t/{{appconf[+taximeter][install\_dir]}}:
> 
> /home/r00t/{{appconf[taximeter][‘install\_dir’]}}:
> 
> /home/r00t/{{appconf[taximeter][install\_dir]}}:
> 
> /home/r00t/[{‘key’: ‘boldface’}, {‘key’: ‘taximeter’}]:  
> boldface taximeter

Please let me know what I’m doing wrong.

Thanks,  
Juan

---

<div class="post-metadata">

**Author:** ![Jesse\_Keating](https://avatars.discourse-cdn.com/v4/letter/j/3bc359/32.png) [@Jesse\_Keating](https://forum.ansible.com/u/Jesse_Keating)\
**Post date:** [January 30, 2014, 5:47pm UTC](https://forum.ansible.com/t/programmatic-variable-name-access/14462/2 "2014-01-30T17:47:11Z")

</div>

Don't quote applist and don't put it in brackets for your with\_items.

with\_items: applist

-jlk

---

<div class="post-metadata">

**Author:** ![Juan\_Uys](https://avatars.discourse-cdn.com/v4/letter/j/9de053/32.png) [@Juan\_Uys](https://forum.ansible.com/u/Juan_Uys)\
**Post date:** [January 30, 2014, 8:24pm UTC](https://forum.ansible.com/t/programmatic-variable-name-access/14462/3 "2014-01-30T20:24:48Z")

</div>

Thanks, that’s a good tip. Turns out I had a similarly-named variable in the role’s vars which mucked with the group vars.

I now also have dest={{appconf[item][‘install\_dir’]}} and it works fine.
