# uri POST with xml template

**URL:** <https://forum.ansible.com/t/uri-post-with-xml-template/28957>\
**Category:** Ansible Project\
**Created:** [November 6, 2018, 1:23pm UTC](https://forum.ansible.com/t/uri-post-with-xml-template/28957 "2018-11-06T13:23:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Leo-San](https://avatars.discourse-cdn.com/v4/letter/l/b782af/32.png) [@Leo-San](https://forum.ansible.com/u/Leo-San)\
**Post date:** [November 6, 2018, 1:23pm UTC](https://forum.ansible.com/t/uri-post-with-xml-template/28957/1 "2018-11-06T13:23:23Z")

</div>

Hey everyone,

so, I am trying to upload an xml template with the uri module, but I cannot find a way which is working. Mostly I am getting the error “Error in XML file. Possible mismatch between resource specified in the URL and XML file”, but the curl command is working with that file.

The last thing I have tried is:

`

- name: upload xml  
uri:  
url: [https://serverFQDN/path](https://serverFQDN/path)  
method: POST  
user: user  
password: password  
src: “{{ lookup(‘template’, ‘dp\_.xml’) }}”  
`

I also tried different things with “body” instead of “src”, which is also not working.

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [November 6, 2018, 3:41pm UTC](https://forum.ansible.com/t/uri-post-with-xml-template/28957/2 "2018-11-06T15:41:21Z")

</div>

Are you sure?  
What file did you upload with curl?  
Because your task specifies a templated file.  
Could it be that the templating has gone wrong in the sense that it  
works for Jinja, but the resulting output isn't valid XML?  
What happens if you skip the template step, i.e. upload a valid XML  
file, i.e. the one that works with curl, but then with ansible?  
So instead of:  
src: "{{ lookup('template', 'dp\_.xml') }}"

just do:

src: /path/to/file/that/works/with/curl.xml

?

If you are going to construct XML, you may want to consider using the  
xml module:  
[https://docs.ansible.com/ansible/latest/modules/xml\_module.html](https://docs.ansible.com/ansible/latest/modules/xml_module.html)

Dick

---

<div class="post-metadata">

**Author:** ![Leo-San](https://avatars.discourse-cdn.com/v4/letter/l/b782af/32.png) [@Leo-San](https://forum.ansible.com/u/Leo-San)\
**Post date:** [November 7, 2018, 5:53am UTC](https://forum.ansible.com/t/uri-post-with-xml-template/28957/3 "2018-11-07T05:53:05Z")

</div>

> What file did you upload with curl?  
> When I upload the file with curl where I replaced the variables with what it needs to be later, it works. Also if I just leave the variables inside, it will be just uploaded with the names of the variables. I am just using the “inventory\_hostname” and the “inventory\_hostname\_short” variables.

> Could it be that the templating has gone wrong in the sense that it works for Jinja, but the resulting output isn’t valid XML?  
> The debug test shows that the variables get replaced correctly by ansible.

> src: /path/to/file/that/works/with/curl.xml  
> I also tried the path for “src”. The same error happened.

Also I am sure the XML file is correct like that as I copied an already existing XML from the Server and used it as a template for mine. (Also everything was correct on the Server after uploading the dp\_.xml with curl).  
So I really don’t know what could have gone wrong.
