Reputation: 143
I have created a list which I want to use as input parameter into the body of the uri
module. When I try to use the list I face an issue with single/double quoting.
- set_fact:
my_entities: "{{ entities.results | json_query('[].json.entities[].entityId') }}"
TASK [set_fact] ****************************************************************
ok: [localhost] => {"ansible_facts": {"my_entities": ["HOST-CD2D2A58FB173BF0", "HOST-41B005A2056B6C03"]}, "changed": false}
- name: test
uri:
url: "XXXXX"
method: POST
headers:
Content-Type: application/json; charset=utf-8
Authorization: XXXXX
return_content: yes
status_code: 201
body: "{\"metadata\":{\"clusterVersion\":\"Mock version\"},\"scope\":{\"entities\":[\"{{ my_entities }}\"]}}
validate_certs: no
body_format: json
When I run the playbook I can see in the failure report that the entities are listed single quoted.
"scope": {
"entities": [
"['HOST-CD2D2A58FB173BF0', 'HOST-41B005A2056B6C03']"
],
When I only select the first value from the list, it works:
body: "{\"metadata\":{\"clusterVersion\":\"Mock version\"},\"scope\":{\"entities\":[\"{{ my_entities | first }}\"]}}
In the report I can see that the entities is like:
"entities": [
"HOST-CD2D2A58FB173BF0"
],
In conclusion, I want to use the complete list {{ my_entities }}
into the uri
POST call where the entities should get populated as ["HOST-CD2D2A58FB173BF0", "HOST-41B005A2056B6C03"]
Upvotes: 1
Views: 991
Reputation: 16997
i dunno if you want list or list of list....
try this:
body: '{"metadata":{"clusterVersion":"Mock version"},"scope":{"entities":[{{my_entities}}] } }'
or this:
body: '{"metadata":{"clusterVersion":"Mock version"},"scope":{"entities":{{my_entities}} } }'
Upvotes: 2