I post below what I ended up using for my utility (Ansible 2.0). This is useful if your json payload is listed on a line (not a file).
this task expects 204 as a success return code.
And since body_format is json, the header is automatically output
- name: add user to virtual host uri: url: http://0.0.0.0:15672/api/permissions/{{ rabbit_virtualhost }}/{{ rabbit_username }} method: PUT user: "{{ rabbit_username }}" password: "{{ rabbit_password }}" return_content: yes body: {"configure":".*","write":".*","read":".*"} body_format: json status_code: 204
it is basically equivalent:
curl -i -u user:pass -H "content-type:application/json" -XPUT http://0.0.0.0:15672/api/permissions/my_vhost/my_user -d '{"configure":".*","write":".*","read":".*"}'
source share