Environment: Carrier 1.9.2, CentOS 6.5
I created a role to download JAVA artifact files (.tar.gz) for 3 different versions of JAVA from Artifactory. I am trying to use the Ansible with_dict function (instead of using with_items).
The following files have been created:
$ cat role / java / defaults / main.yml
--- java_versions: java7_60: version: 1.7.60 group_path: com/oracle/jdk classifier: linux-x64 ext: tar.gz dist_file: "jdk-{{ version }}-{{ classifier }}-{{ ext }}" # dist_file: "jdk-{{item.value.version }}-{{ item.value.classifier }}-{{ item.value.ext }}" dist_url: "{{ artifactory_url }}/{{ group_path }}/{{ version }}/{{ dist_file }}" # dist_url: "{{ artifactory_url }}/{{ item.value.group_path }}/{{ item.value.version }}/{{ dist_file }}" java7_67: version: 1.7.67 group_path: com/oracle/jdk classifier: linux-x64 ext: tar.gz dist_file: "jdk-{{item.value.version }}-{{ item.value.classifier }}-{{ item.value.ext }}" dist_url: "{{ artifactory_url }}/{{ item.value.group_path }}/{{ item.value.version }}/{{ dist_file }}" java8_45: version: 1.8.45 group_path: com/oracle/jdk classifier: linux-x64 ext: tar.gz dist_file: "jdk-{{item.value.version }}-{{ item.value.classifier }}-{{ item.value.ext }}" dist_url: "{{ artifactory_url }}/{{ item.value.group_path }}/{{ item.value.version }}/{{ dist_file }}"
How to set or use dist_file or dist_url variables that depend on other variables defined in the same key (for example, in KEY java7_60)?
Right now, when I try to use either the current dist_file or dist_url variables OR , the commented lines the way they are set (i.e. using item.value.), It does not set the value of these 2 as desired, i.e. depending on other versions of the variables , group_path, classifier, ext, and artifactory_url (which are defined in another common defaults / main.yml file)).
I saw that to use with_dict: inside playbook / task I have to use {{item.value.variable_name}}, but how can I define a variable that depends on others within the same KEY section of the dictionary.
The error message I get when using the above dictionary in the following task:
$ cat role / java / tasks / main.yml :
- name: Download Java/JDK Versions command: wget -q "{{ item.value.dist_url }}" chdir="{{ common_download_dir }}" creates="{{ common_download_dir }}/{{ item.value.dist_file }}" with_dict: "{{ java_versions }}" become_user: "{{ build_user }}"
Error message using dist_file / dist_url (with current setting in roles / java / defaults / main.yml):
TASK: [java | Download Java/JDK Versions] ************************************* failed: [server01.poc.jenkins] => (item={'key': 'java7_60', 'value': {'dist_file': u'jdk-{# version #}-{# classifier #}-{# ext #}', 'ext': 'tar.gz', 'version': '1.7.60', 'dist_url': u'{# artifactory_ur #}/{# group_path #}/{# version #}/{# dist_file #}', 'group_path': 'com/oracle/jdk', 'classifier': 'linux-x64'}}) => {"changed": true, "cmd": ["wget", "-q", "{# artifactory_url #}/{# group_path #}/{# version }/{# dist_file #}"], "delta": "0:00:00.006081", "end": "2015-11-23 12:50:18.383728", "item": {"key": "java7_60", "value": {"classifier": "linux-x64", "dist_file": "jdk-{# version #}-{# classifier #}-{# ext #}, "dist_url": "{
Error message using dist_file / dist_url (with the lines currently commented out in the roles /java/defaults/main.yml):
TASK: [java | Download Java/JDK Versions] ************************************* failed: [server01.poc.jenkins] => (item={'key': 'java7_60', 'value': {'dist_file': u'jdk-{#item.value.version #}-{# item.value.classifier #}-{# item.value.ext #}', 'ext': 'tar.gz', 'version': '1.7.60' , 'dist_url': u'{# artifactory_url #}/{# item.value.group_path #}/{# item.value.version #}/{# dist_file #}', 'group_path': 'com/oracle/jdk', 'classifier': 'linux-x64'}}) => {"changed": true, "cmd": ["wget", "-q", "{# artifactory_url #}/{# item.value.group_path #}/{# item.value.version #}/{# dist_file #}"], "delta": "0:00:00.005900", "end": "2015-11-23 12:36:24.131327", "item": {"key": "java7_60", "value": {"cla ssifier": "linux-x64", "dist_file": "jdk-{#item.value.version #}-{# item.value.classifier #}-{# item.value.ext #}", "dist_url": "{# artifactory_url #}/{# item.value.group_path #}/{# item.value.version #}/{# dist_file #}", "ext": "tar.gz", "group_path": "com/oracle/jdk", "version": "1.7.60"}}, "rc": 4, "start": "2015-11-23 12:36:24.125427", "warnings": ["Consider using get_url module rather than running wget"]}