uri POST with xml template

16 views
Skip to first unread message

Léo-San

unread,
Nov 6, 2018, 8:23:23 AM11/6/18
to Ansible Project
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
       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.

Dick Visser

unread,
Nov 6, 2018, 10:41:50 AM11/6/18
to ansible...@googlegroups.com
On Tue, 6 Nov 2018 at 14:23, Léo-San <speculu...@gmail.com> wrote:
>
> 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.

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

Dick

Léo-San

unread,
Nov 7, 2018, 12:53:05 AM11/7/18
to Ansible Project
> 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.
Reply all
Reply to author
Forward
0 new messages