URI module equivalent for 'curl --upload-file'

HI.

I’ve been trying to deploy a war file to the Tomcat manager using the uri module. I’ve been able to use curl from the command line to achieve this but I can’t seem to translate it into an ansible task that uses the uri module. I could just use the shell module and insert the curl command I’ve been using but I want to stick to best practices and use a module if one if available.

Anyway here’s the curl command that works (ran from my workstation):

`

curl -k -X PUT -u $TOMCAT_USER:$TOMCAT_PW --upload-file someapp.war "https://$SERVER:8443/manager/text/deploy?path=/someapp&update=true"

`

And here’s the latest attempt at an ansible task:

`

- name: Push war to Tomcat manager
  uri:
    url: "https://{{ inventory_hostname }}:8443/manager/text/deploy?path=/someapp&update=true"
    src: /opt/someapp.war'
# tried this instead of src
#    
    user: "{{ tomcat_manager_username }}"
    password: "{{ tomcat_manager_password }}"
    force_basic_auth: yes
    method: PUT
  delegate_to: 127.0.0.1

`

The task passes but it just pushes a blank file to Tomcat instead of the war. I’ve tried subbing out the src param with

`

body: "{{ lookup('file', '/opt/someapp.war') }}"

`

but I get utf-8 encoding errors.

My main question is uploading a binary file not possible with the URI module? And if so what parameters should I use? There’s documentation for using POST with a json file on http://docs.ansible.com/uri_module.html but nothing about uploading binaries.

Thanks in advance.

Ansible version: 1.8.4

I just took a look at the code of the uri module and it looks like src
is accepted but isn't used. (Other file module parameters are also
accepted but not used like mode for file mode). With that support
lacking I don't see any way to upload a binary file via the uri module
currently. So using the command module is going to be your best bet
for now.

If someone is interested in adding src support by opening a pull
request I can take a look at it. Note that if we just work within the
current uri module:
https://github.com/ansible/ansible-modules-core/blob/devel/network/basics/uri.py
then the file will be uploaded from the managed machine. This is
different from the body: "{{ lookup('file', 'filename') }}" approach
given above as that will lookup the file on the ansible controller.
This isn't bad, just different (you can use hosts: localhost or
delegate_to: localhost to get the file from the ansible controller).

-Toshio