nested variables

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:
  "1_7_25":
    i386:
      filename: jre-7u25-linux-i586.tar.gz
      dirname: jre1.7.0_25
    "x86_64":
      filename: jre-7u25-linux-x64.tar.gz
      dirname: jre1.7.0_25
  "1_7_40":
    "i386":
      filename: jre-7u40-linux-i586.tar.gz
      dirname: jre1.7.0_40
    "x64_64":
      filename: server-jre-7u40-linux-x64.tar.gz
      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"
  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\}\.\{$ansible_
architecture}.filename}> dest=/tmp/oracle_java.tar.gz force=yes
  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?

  Best regards
    Peter Hudec

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

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 :slight_smile:

Hi Micheal,

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

Best regards
Peter