Ansible - AUtorizarion tokens with uri module

1,892 views
Skip to first unread message

John McCormack

unread,
Apr 15, 2016, 8:41:15 AM4/15/16
to Ansible Project
Hi
I am trying to use the uri module to connect to my cloud providers API's

curl commands work fine:

curl -i -X POST https://api.madrid.gigas.com/token -d 'login=apiuser&password=apipswd' -H 'Accept: application/json'



curl -v -i -X GET https://api.miami.gigas.com/virtual_machines -H "Authorization: Gigas token=apitoken" -H 'Accept: application/json'



  tasks:
  - uri:
      url: https://api.miami.gigas.com/token
      method: POST
      body: "login=user&password=pass"
      HEADER_Content-Type: "application/x-www-form-urlencoded"
      status_code: 200
      return_content: yes
    register: login

  - uri:
      url: https://api.miami.gigas.com/virtual_machines
      method: GET
      return_content: yes
      HEADER_cookie: "{{login.set_cookie}}"



output from Ansible:


TASK: [uri ] ******************************************************************
ok: [owncloud] => {"access_control_allow_origin": "*", "access_control_expose_headers": "Location, Authorization, X-Total, X-Total-Pages, X-Page, X-Per-Page", "changed": false, "content": "{\"token\": \"gig:3f60064553927bf04e7f4374656fd02cd03e2c11243ef925\", \"expires\": \"1460718309\"}", "content_length": "90", "content_type": "application/json; charset=UTF-8", "date": "Fri, 15 Apr 2016 10:35:09 GMT", "json": {"expires": "1460718309", "token": "gig:3f60064553927bf04e7f4374656fd02cd03e2c11243ef925"}, "redirected": false, "server": "TornadoServer/3.0.1", "set_cookie": "SERVERID=mia2; path=/", "status": 200}

TASK: [uri ] ******************************************************************
failed: [owncloud] => {"access_control_allow_origin": "*", "access_control_expose_headers": "Location, Authorization, X-Total, X-Total-Pages, X-Page, X-Per-Page", "content": "{\"error\": \"Unauthorized: Please provide an authentication token\"}", "content_length": "65", "content_type": "application/json; charset=UTF-8", "date": "Fri, 15 Apr 2016 10:35:10 GMT", "failed": true, "json": {"error": "Unauthorized: Please provide an authentication token"}, "redirected": false, "server": "TornadoServer/3.0.1", "status": 401}
msg: Status code was not 200

FATAL: all hosts have already failed -- aborting

Anyone any ideas?

I have tried different combinations of the ansible yaml files, but nothing seems to work for me... Generally end up with the same error.

Priyanka Reddy

unread,
Aug 25, 2016, 10:59:50 PM8/25/16
to Ansible Project
Hi WHERE YOU ABLE TO SOLVE THIS ISSUE?


I AM ALSO GETTING THE SAME ERROR?

Mohammed Reehan

unread,
Jul 18, 2022, 1:45:45 PM7/18/22
to Ansible Project
Any update on this

Dick Visser

unread,
Jul 18, 2022, 3:53:31 PM7/18/22
to ansible...@googlegroups.com
On Mon, 18 Jul 2022 at 19:45, Mohammed Reehan <mohd....@gmail.com> wrote:
>
> Any update on this

Someone already asked the same thing after 4 months and got no response.
So asking again after 6 years will almost certainly not get you a
response either.
Start a new question with your own data/logs/etc instead of
resurrecting ancient threads.
Reply all
Reply to author
Forward
0 new messages