URI module cannot use body and src together

Hi,

URI module cannot use body and src together.

Binary file and body parameter cannot be posted.

I’ve tried to make this work but can’t find any Ansible documentation stating how to do this using the URI module. I’m able to use curl with the SHELL module, but not ideal approach.
Any guidance would be appreciate it.

Regards,
Wilber H

It sounds like you are trying to do a multipart post. In which case, just use body, and follow the example named “Upload a file via multipart/form-multipart”

https://docs.ansible.com/ansible/latest/collections/ansible/builtin/uri_module.html

Hi Matt,

I followed the steps in the section and tried several combinations of it and still get this message or something similar -

“msg”: “value of the body_format must be one of: form-urlencoded, json, raw, got: form-multipart”

*note: this is the body section of the URI module/task -
file1:
filename: “somefilename.bin”
mime_type: application/octet-stream
todo: “dosomething”

*But when I decide to use the SHELL module and the curl command it works -
curl -X POST --url https://someaddress/worktodo
-k
-H ‘Accept-Type: application/json’ \

-H ‘Content-Type: multipart/form-data’ \

-H 'Cookie: ‘somecookie’ \

-F ‘todo=dosomething’

-F ‘binaryfile=@somefilename.bin’