# nested variables

**URL:** <https://forum.ansible.com/t/nested-variables/13687>\
**Category:** Ansible Project\
**Created:** [October 15, 2013, 9:10pm UTC](https://forum.ansible.com/t/nested-variables/13687 "2013-10-15T21:10:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hudec\_Peter](https://avatars.discourse-cdn.com/v4/letter/h/a87d85/32.png) [@Hudec\_Peter](https://forum.ansible.com/u/Hudec_Peter)\
**Post date:** [October 15, 2013, 9:10pm UTC](https://forum.ansible.com/t/nested-variables/13687/1 "2013-10-15T21:10:44Z")

</div>

Hi all,

I read quite a lot of docs about the nested variables but I'm still not  
able to find the right syntax.

file: role/tomcat/vars/main.yml  
java:  
&nbsp;&nbsp;"1\_7\_25":  
&nbsp;&nbsp;&nbsp;&nbsp;i386:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;filename: jre-7u25-linux-i586.tar.gz  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dirname: jre1.7.0\_25  
&nbsp;&nbsp;&nbsp;&nbsp;"x86\_64":  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;filename: jre-7u25-linux-x64.tar.gz  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dirname: jre1.7.0\_25  
&nbsp;&nbsp;"1\_7\_40":  
&nbsp;&nbsp;&nbsp;&nbsp;"i386":  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;filename: jre-7u40-linux-i586.tar.gz  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dirname: jre1.7.0\_40  
&nbsp;&nbsp;&nbsp;&nbsp;"x64\_64":  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;filename: server-jre-7u40-linux-x64.tar.gz  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dirname: jdk1.7.0\_40

file: roles/tomcat/defaults/main.yml  
# tomcat playbook  
java\_version: "1\_7\_40"  
java\_install\_dir: /opt/oracle\_java

file: roles/tomcat/tasks/java.yml  
- name: "[java] download java install file"  
&nbsp;&nbsp;action: get\_url  
url=http://\<download.server.internal\>/java/oracle-java/${java.{$java\_versio  
n}.{$ansible\_architecture}.filename}  
\<[http://zabbix.sk-nic.sk/java/oracle-java/$\{java\.\{$java\_version\}\.\](http://zabbix.sk-nic.sk/java/oracle-java/$%5C%7Bjava%5C.%5C%7B$java%5C_version%5C%7D%5C.%5C){$ansible\_  
architecture}.filename}\> dest=/tmp/oracle\_java.tar.gz force=yes  
&nbsp;&nbsp;tags: test

My problem is how to write nested variable in the URL. This should  
download java JRE based on the version and server architecture. I tried  
almost all combination if {{ }}, ${}, {$}, $ ….  
I'm using similar concept for creating users and it's working.  
I'm using lastest devel version /form git/ of the ansible.

Does anybody have more experience with nested variables?

&nbsp;&nbsp;Best regards  
&nbsp;&nbsp;&nbsp;&nbsp;Peter Hudec

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [October 15, 2013, 11:37pm UTC](https://forum.ansible.com/t/nested-variables/13687/2 "2013-10-15T23:37:42Z")

</div>

This is because you are using the scary old style variable syntax, and also getting a bit wrong 🙂

Instead of this:

/${java.{$java\_versio  
n}.{$ansible\_architecture}.filename}

Do this:

{{ java[java\_version][ansible\_architecture][‘filename’] }}

This is why the Ansible documentation, which I do recommend reading, only documents this way of doing things 🙂

---

<div class="post-metadata">

**Author:** ![Hudec\_Peter](https://avatars.discourse-cdn.com/v4/letter/h/a87d85/32.png) [@Hudec\_Peter](https://forum.ansible.com/u/Hudec_Peter)\
**Post date:** [October 16, 2013, 8:17am UTC](https://forum.ansible.com/t/nested-variables/13687/3 "2013-10-16T08:17:06Z")

</div>

Hi Micheal,

Thanks, this works.  
I need to update all my playbook wriitem in old scary style.

Best regards  
Peter
