Facing issue with URI module

48 views
Skip to first unread message

Himanshu Pupneja

unread,
Mar 2, 2020, 6:43:57 AM3/2/20
to Ansible Project
I am facing issue in URI module, Could you please help me in this
It works well with postman and curl command.



Below module is failing

=============================
  - name: Connect to website
    uri:
      headers:
        apikey: "xyz1"
        apitoken: "xyz2
        cmd: "xyz"
      body_format: "form-urlencoded"
      body:
        abc: "123"
        def: "456"
      return_content: yes
      validate_certs: no
      method: POST
      timeout: 60
      use_proxy: no
================================

===========Error Output============

"msg": "Status code was 401 and not [200]: HTTP Error 401: Unauthorized",

========================


============Curl - which is working==========

curl --location --request POST 'https://xyz.com/api.php' \

--header 'apikey: xyz' \

--header 'apitoken: xyz' \

--header 'cmd: xyz' \

--data-urlencode 'abc=123' \

--data-urlencode 'def=456'


Himanshu Pupneja

unread,
Mar 2, 2020, 7:02:04 AM3/2/20
to Ansible Project
Just FYI) values in both headers(URI module and curl) are similar

Dick Visser

unread,
Mar 2, 2020, 7:02:56 AM3/2/20
to ansible...@googlegroups.com
If you use try with -vvv then you can see the parameters with which
the module was invoked.
> --
> 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 view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/1f433a02-4835-4cc7-a05d-197cf302c6cc%40googlegroups.com.



--
Dick Visser
Trust & Identity Service Operations Manager
GÉANT

Vishal Bobade

unread,
Mar 2, 2020, 7:15:18 AM3/2/20
to ansible...@googlegroups.com
Do u have any reverse proxy configured please check that. 

Himanshu Pupneja

unread,
Mar 3, 2020, 1:29:44 AM3/3/20
to Ansible Project
Hi Vishal,
Does it make any difference in proxy when it is working fine with postman and curl and not with URI module?

Reply all
Reply to author
Forward
0 new messages