How can I reuse variables in other variables in Ansible (2.1.x) without causing recursive loops?
Setup
Consider this roles/<role>/defaults/main.yml
file:
---
liquibase:
version: "3.5.3"
download_file: "liquibase-{{liquibase.version}}-bin.tar.gz"
# I also tried this alternative with a similar result:
# download_file: "liquibase-{{liquibase[version]}}-bin.tar.gz
...
and this roles/<role>/tasks/main.yml
file:
---
- name: Liquibase | Download
debug:
msg: "download_file: {{liquibase.download_file}}"
...
Error
I'd expect the variable liquibase.download_file
to have the value liquibase-3.5.3-bin.tar.gz
but when I run a playbook using this role, I get the following error:
...
TASK [liquibase : Liquibase | Download] *******************************************
fatal: [localhost]: FAILED! => {"failed": true, "msg": "...: recursive loop detected in template string: liquibase-{{liquibase.version}}-bin.tar.gz"}
...
My Use Case
Obviously I want to download Liquibase and I want to let the role's user decide which version to use. I also want to give the possibility to completely override the download location (file, URL, etc.), e.g. for using a company's FTP server or similar.