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.
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') }}"
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.