ISSUE TYPE
- Feature Idea
COMPONENT NAME
Template module and URI module
ANSIBLE VERSION
ansible 2.1.1.0
OS / ENVIRONMENT
Centos 6.7
SUMMARY
I need to pass to a template several variables, from 2 different tasks with a loop (with_items). This template is a JSON wich is used by another task (URI)
STEPS TO REPRODUCE
- name: Task1, loop 2 times
shell: jq -r ".collection|.[]|select(.name==\"{{item.vlan}}\").id" /tmp/temporal4
register: id_vlan
with_items: "{{ nic | default () }}"
- name: Task2, loop 2 times
shell: jq ".collection|.[]|select(.ip==\"{{item.item.ip}}\").id" /tmp/vlan{{item.stdout}}
register: id_ip
with_items: "{{id_vlan.results}}"
Once these tasks are executed, we have 2 variables (id_vlan / id_ip), with 2 values stored in each one.
Now, i have another task, wich does a call API, using a JSON. I show you the task, and the formar of the JSON.
- name: API CALL
uri:
url: "https://xxxx/api/virtualmachines/"
method: POST
force_basic_auth: yes
validate_certs: no
body: "{{ lookup('template','/tmp/requestpayload.j2') }}"
body_format: json
status_code: 201
dest: "/tmp/temporal"
},
"title":"{{ip}}",
"rel":"",
"type":"application/v+json",
"href": "https://xxxxx/api/{{id_vlan.results}}/{{id_ip.results}}"
},
EXPECTED RESULTS
The expected results its the execution of the task ‘API CALL’ using the json with the differents values of the vars {{id_vlan.results}} and {{id_ip.results}}, for example:
},
"title":"192.168.1.1",
"rel":"",
"type":"application/v+json",
"href": "https://xxxxx/api/12345/6789"
},
and
},
"title":"192.168.1.2",
"rel":"",
"type":"application/v+json",
"href": "https://xxxxx/api/2222/1111"
},
ACTUAL RESULTS
I have not actual results because i dont know how to do it. At this moment because i have using the tasks with no loops, in other words, im using until now the JSON with only one value of each variable.
I think that i need a bucle for of jinja2, but i dont know how to apply it.
I hope you unterstand me