I'm having an issue adding an element to an array. What i need to do is...
1) get an array list of IDs from an api using the uri module (no issues here)
2) add an element to this array (issue here!)
3) send a PUT with the updated array using uri (no issues here)
====tasks start====
- name: get data from endpoint 1
register: reg_endpoint1
- name: get data from endpoint 2
register: reg_endpoint2
- name: make an array element from id from endpoint 1, then add this to endpoint 2 array, save as updated_array
set_fact: updated_array="{{ reg_endpoint2.json.array_with_many_elements }} + [ {{ reg_endpoint1.json.id_list[0].id }} ]"
- name: put data with updated_array
uri:
method=PUT
HEADER_api_key="xxxxxxxxxxxx"
HEADER_Content-Type="application/json"
body={{ lookup('template','/full/path/to/file.json.j2') }}
====tasks end====
====/full/path/to/file.json.j2====
'{
"something1": {
"otherthing2": {
"thatotherthing3": {{ updated_array }}
}
}
}'
==========================
My output error contains:
<server1> REMOTE_MODULE uri method=PUT url=
https://someapi.com/endpoint3.json HEADER_api_key="xxxxxxxxxxxx" HEADER_Content-Type="application/json" body='{ "something1": { "otherthing2": { "thatotherthing3": [13651171, 13651172] + [ 12994448 ] } } }'
As you can see the array is malformed from the set_fact task:
[13651171, 13651172] + [ 12994448 ]
Question:
How do I make {{ updated_array }} look like this:
[13651171, 13651172, 12994448 ]
Thanks!