I have a list
- name: List
set_fact:
array1:
- param1: "efg"
param2: "abdc"
param3: "nsdadsd"
param4: "dadas dsadasda"
which looks like:
"array1": [
{
"param1": "efg",
"param2": "abdc",
"param3": "nsdadsd",
"param4": "dadas dsadasda"
}
]
Which I want to to send in a body of the following API call
- name: API call
delegate_to: localhost
uri:
url: https://some_url/abcd/
validate_certs: false
method: POST
body_format: json
headers:
X-some-APIKey: "{{api_token}}"
body:
'{
"{{array1}}"
}'
register: api_output
For this I get an error:
"msg": "Unable to pass options to module, they must be JSON serializable: Object of type 'set' is not JSON serializable"
I found on internet that the problem could be that it's not a string that is passed but a "set" and one of the answers was to convert it to a string, so I tried this
- name: array2
set_fact:
array2: "{{array1 | string }}"
Also tried different variations with quotes, either ' or " for the values and even parameters, but nothing helped.
Update:
Let me add that just for the test I changed the array to be just with one item, and still getting "serializable" error. So I'm thinking maybe it's not the array which is a problem, but syntax for calling this variable from an API?
- name: array
set_fact:
array1:
- abdcdef
SOLUTION: Update no2.
Problem was with two things. First there was Content-Type: "application/json" missing from API call. Second was that this API web service does not accept arrays.