title: Is there a way to insert raw escaped json in json body in ansible
body: <p>See below first call which works. This is an example of how I create a template on my system. Notice I have to use {% raw %} ... {% endraw %} so ansible doesn't try to interpret the variables in my template.</p>
  <pre class="lang-none prettyprint-override"><code>    - name: Create a template : OK
        uri:
          url: https://{{ ip }}/api/v1/templates
          method: POST
          headers:
            Authorization: &quot;{{ token }}&quot;
            Content-Type: application/json
          body: |
            {
              &quot;name&quot;: &quot;{{ template_name }}&quot;,
              &quot;type&quot;: &quot;v1&quot;,
              &quot;description&quot;: &quot;{{ template_name }}&quot;,
              &quot;content&quot;: &quot;template: |  {% raw %}\n    {\n   \&quot;class\&quot;: \&quot;ABC\&quot;,\n      \&quot;param\&quot;: {{param1::integer}}\n  }{% endraw %}&quot;
            }
          body_format: json
          timeout: 60
          status_code: 202
          validate_certs: false
        register: json_response
  </code></pre>
  <p><strong>Output OK:</strong></p>
  <pre><code>    ok: [notahost] =&gt; {
          &quot;invocation&quot;: {
              &quot;module_args&quot;: {
                  &quot;body&quot;: {
                      &quot;content&quot;: &quot;template: |  \n    {\n   \&quot;class\&quot;: \&quot;ABC\&quot;,\n      \&quot;param\&quot;: {{param1::integer}}\n  }&quot;, 
                      &quot;description&quot;: &quot;test1&quot;, 
                      &quot;name&quot;: &quot;test1&quot;, 
                      &quot;type&quot;: &quot;v1&quot;
                  }, 
                  &quot;body_format&quot;: &quot;json&quot;, 
  </code></pre>
  <p>Now, I am trying to move the content of the template outside in a file called template1.j2.</p>
  <p><strong>template1.j2</strong>:</p>
  <pre class="lang-none prettyprint-override"><code>    {% raw %} 
      {
        &quot;class&quot;: &quot;ABC&quot;,
        &quot;param&quot;: {{param1::integer}}
      } 
      {% endraw %}
  </code></pre>
  <p>I insert the template template1.j2 into my JSON body (noticed I added the {% raw %} ... {% endraw %} inside the template).</p>
  <pre class="lang-none prettyprint-override"><code>    - name: Create a template NOK
        uri:
          url: https://{{ ip }}/api/v1/templates
          method: POST
          headers:
            Authorization: &quot;{{ token }}&quot;
            Content-Type: application/json
          body: |
            {
              &quot;name&quot;: &quot;{{ template_name }}&quot;,
              &quot;type&quot;: &quot;v1&quot;,
              &quot;description&quot;: &quot;{{ template_name }}&quot;,
              &quot;content&quot;: &quot;template: | {{ lookup('file','template1.j2') }}&quot;
            }
          body_format: json
          timeout: 60
          status_code: 202
          validate_certs: false
        register: json_response
  </code></pre>
  <p><strong>Output NOK:</strong></p>
  <pre><code>    fatal: [notahost]: FAILED! =&gt; {
          &quot;content&quot;: &quot;{\&quot;message\&quot;:\&quot;request body has an error: failed to decode request body: invalid character '\\\\n' in string literal\&quot;}\n&quot;, 
          &quot;invocation&quot;: {
              &quot;module_args&quot;: {
                  &quot;body&quot;: &quot;{\n  \&quot;name\&quot;: \&quot;test2\&quot;,\n  \&quot;type\&quot;: \&quot;v1\&quot;,\n  \&quot;description\&quot;: \&quot;test2\&quot;,\n  \&quot;content\&quot;: \&quot;template: |  \n{\n    \&quot;class\&quot;: \&quot;ABC\&quot;,\n    \&quot;param\&quot;: {{param1::integer}}\n} \n\&quot;\n}\n&quot;, 
                  &quot;body_format&quot;: &quot;json&quot;, 
  </code></pre>
  <p>For some reason, it looks like the way I am doing this doesn't work, ansible still try to interpret the variable in my template at creation.</p>
  <p>Any idea on how to get his work with my template outside the ansible task?</p>
  <p><em>PS: I have tried to load the template file using the shell ansible module and that did not help.</em></p>
  <p>Thanks &amp; Regards,
  Romain</p>