# Variable in "body" parameter of "uri" module

**URL:** <https://forum.ansible.com/t/variable-in-body-parameter-of-uri-module/29124>\
**Category:** Ansible Project\
**Created:** [November 27, 2018, 12:56pm UTC](https://forum.ansible.com/t/variable-in-body-parameter-of-uri-module/29124 "2018-11-27T12:56:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ilya\_Ulis](https://avatars.discourse-cdn.com/v4/letter/i/43a26b/32.png) [@Ilya\_Ulis](https://forum.ansible.com/u/Ilya_Ulis)\
**Post date:** [November 27, 2018, 12:56pm UTC](https://forum.ansible.com/t/variable-in-body-parameter-of-uri-module/29124/1 "2018-11-27T12:56:26Z")

</div>

Hi all!

This is my task that works:

`

- name: Stop services on ambari  
uri:  
url: http://{{ inventory\_hostname }}:8080/api/v1/clusters/{{ hostvars[inventory\_hostname].cluster\_name }}/services/{{ service }}  
method: PUT  
force\_basic\_auth: yes  
user: “{{ ambari\_admin\_user }}”  
password: “{{ ambari\_admin\_password }}”  
headers: ‘{“X-Requested-By”:“ambari”}’  
body: “{"RequestInfo":{ "context":"Stop services via REST"},"ServiceInfo":{"state":"INSTALLED"}}”  
status\_code: 200,201,202  
body\_format: raw  
timeout: 120  
return\_content: yes  
register: returned\_from\_cluster  
when: “‘AMBARI-SERVER’ in group\_names”  
`

I want to change the Stop services via REST part to Stop {{ service }} via REST.  
But the playbook fault with:  
`"msg": "Status code was -1 and not [200, 201, 202]: An unknown error occurred: must be string or buffer, not dict"`

I tried to run the playbook with -vvv and saw the diffenence.

This one without variable:

`"body": "{\\"RequestInfo\\":{ \\"context\\":\\"Stop services via REST\\"},\\"ServiceInfo\\":{\\"state\\":\\"INSTALLED\\"}}"`

And this one with variable:

`"body": {"RequestInfo": {"context": "Stop NIFI_REGISTRY via REST"}, "ServiceInfo": {"state": "INSTALLED"}}`

How can I avoid this evaluation?

---

<div class="post-metadata">

**Author:** ![Ilya\_Ulis](https://avatars.discourse-cdn.com/v4/letter/i/43a26b/32.png) [@Ilya\_Ulis](https://forum.ansible.com/u/Ilya_Ulis)\
**Post date:** [November 28, 2018, 9:32am UTC](https://forum.ansible.com/t/variable-in-body-parameter-of-uri-module/29124/2 "2018-11-28T09:32:19Z")

</div>

Ok, I have found a solution.  
First of all, for some bug in Ambari I have to use raw body format and no json.  
So I have changed the body\_format to json and appended “Content-Type”:“text/plain” to the headers parameter.  
Now my headers parameter looks like:

`  
headers: ‘{“X-Requested-By”:“ambari”, “Content-Type”:“text/plain”}’

`  
Now everything works properly.
