Send payload using uri module

306 views
Skip to first unread message

Sharwari Phadnis

unread,
Oct 14, 2015, 6:59:29 AM10/14/15
to Ansible Project
I am trying to send a payload(in JSON) to a destination mentioned in the URL. For this purpose I am using uri module and POST method. How can I send it using uri module? I am using ansible version 1.9.1 and when I tried to use body parameter for uri module it shows the following error: body is not a legal parameter in an Ansible task or handler.

David Karban

unread,
Oct 14, 2015, 7:03:29 AM10/14/15
to ansible...@googlegroups.com
Hi, 

this error usually means problem in indentation, body souhld be two spaces deeper I guess. But cannot be sure, as you have not sent your task here :).

David Karban
Linux server specialist/Specialista na správu linuxových serverů
www.karban.eu

2015-10-14 12:59 GMT+02:00 Sharwari Phadnis <sharwar...@gmail.com>:
I am trying to send a payload(in JSON) to a destination mentioned in the URL. For this purpose I am using uri module and POST method. How can I send it using uri module? I am using ansible version 1.9.1 and when I tried to use body parameter for uri module it shows the following error: body is not a legal parameter in an Ansible task or handler.

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/a396f9dd-370d-44d9-9a21-149901848f88%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Sharwari Phadnis

unread,
Oct 14, 2015, 7:05:41 AM10/14/15
to Ansible Project
So, to send payload  body parameter could be used?

David Karban

unread,
Oct 14, 2015, 7:12:12 AM10/14/15
to ansible...@googlegroups.com
Hi, 

please send that one task here, so we can see what you are actually doing, it will help to understand, thanks.

David Karban
Linux server specialist/Specialista na správu linuxových serverů
www.karban.eu

Message has been deleted

Sharwari Phadnis

unread,
Oct 14, 2015, 8:22:21 AM10/14/15
to Ansible Project
---
- hosts: localhost
  tasks:
    - uri:
      url: https://url/to/the/dest/server
      method: POST
      user: admin
      password: default
      force_basic_auth: yes
      body: '{JSON payload}'
      body_format: json
      register: payloadop

    - name: Print command output
      action: command echo item
      with_items: payloadop.stdout

Igor Cicimov

unread,
Oct 21, 2015, 12:18:09 AM10/21/15
to Ansible Project
Well first of all if you check the module docs http://docs.ansible.com/ansible/uri_module.html you can see that body_format was introduced in ansible 2.0 so you can't use it in 1.9.1

It also shows an example of supplying the json file to the body parameter that looks much cleaner than what you are trying to do:

body: "{{ lookup('file','issue.json') }}"

Have you tried that?

Sharwari Phadnis

unread,
Oct 21, 2015, 12:34:07 AM10/21/15
to ansible...@googlegroups.com

Yes, I tried that. It worked.

Thanks.

--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/pUJfN9RL-NA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.

To post to this group, send email to ansible...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages