I have a bit of JSON I need to send to an API via Ansible, URI module.
It's failing due to an undefined var in the JSON. Specifically It's failing due to this line.
"message": "{{message}}"
The thing here is that I need this line as is. There is no var meant to substitute {{message}}, the line has to be...
"message": "{{message}}"
How do I tell Ansible or the URI module to just send the contents as it is?
Original JSON
"message":"{{ policy.message | default('{{message}}') }}",
I've not tried slapping {% raw %}
, {% endraw %}
lines to the start and end of the JSON, because I do need to do some logic to it first.
Also it's failing for that var because it's the first one like that in the JSON. I have 5 more like it in there.
The Task
As I think it will help clear some things up, here are the tasks...
- name: apply_policy.yml | render policy
set_fact:
_policy_rendered: "{{ lookup('template', 'policy.json.j2') | string }}"
check_mode: no
# Calls API with POST method to CREATE policy
- name: apply_policy.yml | CREATE policy
uri:
url: https://api.xxxxx/policies/
headers:
content-type: application/json
Host: api.xxxxx.com
Connection: keep-alive
Authorization: GenieKey {{key}}
method: POST
body: "{{ _policy_rendered }}"
return_content: yes
body_format: json
status_code: [201]