# uri\_module - json post

**URL:** <https://forum.ansible.com/t/uri-module-json-post/18567>\
**Category:** Ansible Project\
**Created:** [June 22, 2015, 8:45pm UTC](https://forum.ansible.com/t/uri-module-json-post/18567 "2015-06-22T20:45:16Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Darvin\_Denmian](https://avatars.discourse-cdn.com/v4/letter/d/c68b51/32.png) [@Darvin\_Denmian](https://forum.ansible.com/u/Darvin_Denmian)\
**Post date:** [June 22, 2015, 8:45pm UTC](https://forum.ansible.com/t/uri-module-json-post/18567/1 "2015-06-22T20:45:16Z")

</div>

Hi guys,

this is the first time I ever use the “uri\_module” and I’m facing a problem that I just can’t solve… here it is

- name: Sending Stash to Sensu - {{ item }}

uri:  
url=[http://10.0.0.8:4567/stashes](http://10.0.0.8:4567/stashes)  
method=POST  
body\_format=json  
body=“{“path”: “silence/{{ item }}”,“content”: {“reason”: “Automatic Scale Down”},“expire”: 28800}”  
HEADER\_Content-Type=“application/json;charset=utf-8”  
status\_code=200  
with\_items:

- c3\_imagens\_name  
tags:
- stash

When I try to execute this piece of code I got the following error:

ERROR: Syntax Error while loading YAML script, ec2\_rotate\_imagens.yml  
Note: The error may actually appear before this position: line 76, column 22

body\_format=json  
body=“{“path”: “silence/{{ item }}”,“content”: {“reason”: “Automatic Scale Down”},“expire”: 28800}”  
^  
We could be wrong, but this one looks like it might be an issue with  
missing quotes. Always quote template expression brackets when they  
start a value. For instance:

with\_items:

- {{ foo }}

Should be written as:

with\_items:

- “{{ foo }}”

I’m trying to POST something like this (using curl):

/usr/bin/curl -XPOST ‘[http://10.0.0.8:4567/stashes](http://10.0.0.8:4567/stashes)’ -d ‘{  
“path”: “silence/ip-10-0-4-217”,  
“content”: {  
“reason”: “Automatic Scale Down”  
},  
“expire”: 28800  
}’

Could you please guys give me some help?

Thanks in advance

---

<div class="post-metadata">

**Author:** ![Rob\_White](https://avatars.discourse-cdn.com/v4/letter/r/71c47a/32.png) [@Rob\_White](https://forum.ansible.com/u/Rob_White)\
**Post date:** [June 22, 2015, 11:44pm UTC](https://forum.ansible.com/t/uri-module-json-post/18567/2 "2015-06-22T23:44:04Z")

</div>

Escape your double quotes

body=“{"path": "silence/{{ item }}","content": {"reason": "Automatic Scale Down"},"expire": 28800}”

---

<div class="post-metadata">

**Author:** ![Erick\_Vitor\_de\_Barro](https://avatars.discourse-cdn.com/v4/letter/e/ee7513/32.png) [@Erick\_Vitor\_de\_Barro](https://forum.ansible.com/u/Erick_Vitor_de_Barro)\
**Post date:** [June 23, 2015, 12:44pm UTC](https://forum.ansible.com/t/uri-module-json-post/18567/3 "2015-06-23T12:44:21Z")

</div>

Hi Rob,

thanks for your reply. I’ll try that.

---

<div class="post-metadata">

**Author:** ![Erick\_Vitor\_de\_Barro](https://avatars.discourse-cdn.com/v4/letter/e/ee7513/32.png) [@Erick\_Vitor\_de\_Barro](https://forum.ansible.com/u/Erick_Vitor_de_Barro)\
**Post date:** [June 26, 2015, 5:30pm UTC](https://forum.ansible.com/t/uri-module-json-post/18567/4 "2015-06-26T17:30:20Z")

</div>

Hi guys,

I solved the issue with the following adjustments:

- name: Sending Stash to Sensu - {{ item }}  
uri:  
url=[http://10.0.0.8:4567/stashes](http://10.0.0.8:4567/stashes)  
method=POST  
body\_format=json  
body=‘{“path”:“silence/{{ item }}”,“content”:{“reason”:“Automatic Scale Down”},“expire”:28800}’  
status\_code=201  
HEADER\_Content-Type=“application/json”  
with\_items: c3\_imagens\_name  
tags:
- stash

Thanks !

---

<div class="post-metadata">

**Author:** ![Barry\_Kaplan](https://avatars.discourse-cdn.com/v4/letter/b/48db29/32.png) [@Barry\_Kaplan](https://forum.ansible.com/u/Barry_Kaplan)\
**Post date:** [June 27, 2015, 1:00am UTC](https://forum.ansible.com/t/uri-module-json-post/18567/5 "2015-06-27T01:00:26Z")

</div>

I simply copied the 2.0 uir.py into my ./modules. It supports body\_format=json which will convert the body dict into json as well as set the appropriate headers.

Indeed I have done this for several modules that are scheduled for 2.0 or are pending PRs. Ansible is incredibly flexible in this manner. Just need be sure to clean up the hacks when the modules are actually released.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [June 30, 2015, 4:30am UTC](https://forum.ansible.com/t/uri-module-json-post/18567/6 "2015-06-30T04:30:01Z")

</div>

that will work for most modules, but some do depend on features only  
in the version they were merged, so this will work most of the time  
but not 100%.
