title: How to use variable inside json string in Ansible uri module?
body: <p>Using ansible 2.5.3 on ubuntu 16.10.</p>
  
  <p>I need to include a variable in a JSON string for the body tag of the Ansible uri module. I have tried various things. My latest try looks like this in the below task in a role:</p>
  
  <pre><code>- name: REST POST Example
    uri:
      url: "{{ webapp_url }}/api/orgs"
      method: POST
      return_content: yes
      body: "{ \"name\": \"{{ project_name }}\" }"
      validate_certs: no
      user: "{{ user }}"
      password: "{{ password }}"
      force_basic_auth: yes
      headers:
        Content-Type: "application/json"
  </code></pre>
  
  <p>In my playbook I define the <code>project_name</code> variable:</p>
  
  <pre><code>---
  
  - hosts: all
    gather_facts: no
    vars:
        project_name: "SAMPLE_PROJECT"
  </code></pre>
  
  <p>But when I run the playbook the <code>project_name</code> variable does not seem to get expanded correctly:</p>
  
  <blockquote>
    <p>An exception occurred during task execution. To see the full traceback, use -vvv. The error was: TypeError: unhashable type<br>
    fatal: [localhost]: FAILED! => {"changed": false, "content": "", "msg": "Status code was -1 and not [200]: An unknown error occurred: unhashable type", "redirected": false, "status": -1, "url": "<a href="https://webapp/api/orgs" rel="nofollow noreferrer">https://webapp/api/orgs</a>"}</p>
  </blockquote>
  
  <p>In the above role/task. If I hardcode the body like:</p>
  
  <pre><code>body: "{\"name\": \"SAMPLE_PROJECT\"}"
  </code></pre>
  
  <p>it works fine. But I cannot do that I need the variable in there. Any suggestions on how to fix:</p>
  
  <pre><code>body: "{ \"name\": \"{{ project_name }}\" }"
  </code></pre>
  
  <p>?</p>