Ansible version 1.9.2.
Does Ansible support variable expansion inside a variable when evaluating it?
I have a task to download 3 zip files from Artifactory.
Instead of writing 3 separate tasks in a role, I used a listenable loop in the tutorial. In the Ansible role default / main.yml, I have all the necessary variables defined / available for the ie Jmeterplugins_extras_artifactory_url role and others (standard / webdriver) perf_tests roles are visible.
--- #- Download and install JMeterPlugins # Use get_url when Ansible is 2.0+ is available on the machine (otherwise, we can't use get_url) thus, using wget. - name: Download JMeterPlugins-* command: wget {{ jmeterplugins_{{ item.plugin }}_artifactory_url }} chdir="{{ common_download_dir }}" creates="{{ common_download_dir }}/{{ jmeterplugins_{{ item.plugin }}_file }}" with_items: - { plugin: 'extras' } - { plugin: 'standard' } - { plugin: 'webdriver' }
But with the code above, I get an error message (as shown below):
15:58:57 TASK: [perf_tests | Download JMeterPlugins-*] ********************************* 15:58:57 <jmeter01.super.fast.jenkins> ESTABLISH CONNECTION FOR USER: cmuser on PORT 22 TO jmeter01.super.fast.jenkins 15:58:57 fatal: [jmeter01.super.fast.jenkins] => Failed to template wget {{ jmeterplugins_{{ item.plugin }}_artifactory_url }} chdir="{{ common_download_dir }}" creates="{{ common_download_dir }}/{{ jmeterplugins_{{ item.plugin }}_file }}": template error while templating string: expected token 'variable_end', got '{' 15:58:57 15:58:57 FATAL: all hosts have already failed -- aborting 15:58:57 15:58:57 PLAY RECAP ******************************************************************** 15:58:57 to retry, use: --limit @/home/cmuser/perf_tests.retry 15:58:57 15:58:57 jmeter01.super.fast.jenkins : ok=23 changed=6 unreachable=1 failed=0
It is not possible to support a variable extension / evaluation if the variable contains another variable (especially when I use a loop).
I just do not want to expand my simple loop task to 3 different tasks for downloading zip files for jmeterplugins_extras, jmeterplugins_standard and jmeterplugins_webdriver separately. It seems that the error is related to Jinja.
How can I use the value of var giga in another variable, that is, if var contains giga , then I should get the value of the variable special_giga_variable ({{special_ {var}} _ variable}})? where var is set by default to /main.yml as:
var: giga
variables jinja2 ansible ansible-playbook
Arun sangal
source share