dictionary key as variable

Hi,
I’m developing a generic tomcat role, it gets version number as variable;

roles:

  • { role: tomcat, version: “8.0.33” }

I’ve mentioned download urls for some major versions at vars.yml

file:

“8”: “…apache-tomcat-8.0.33.tar.gz”

“7”: “…apache-tomcat-7.0.33.tar.gz”

I would like to use this dictionary at role main.yml for given version number;

Question is, how can I use external variable as dictionary key in role task.

I tried those;

  • name: copy tomcat to server

copy: src=files/{{file[{{version}}]}} dest=/tmp/

  • name: copy tomcat to server

copy: src=files/{{file.version}} dest=/tmp/

  • name: copy tomcat to server

copy: src=files/{{file}}.{{version}} dest=/tmp/

Thank you.

You cannot nest {{ }}, instead you want:

{{ file[version] }}

Thanks Matt, it works.

You might want to rename your variable (file) so it does not have the
same name as a existing module. Just to avoid trouble...

Johannes