# Ansible - AUtorizarion tokens with uri module

**URL:** <https://forum.ansible.com/t/ansible-autorizarion-tokens-with-uri-module/21169>\
**Category:** Ansible Project\
**Created:** [April 15, 2016, 10:37am UTC](https://forum.ansible.com/t/ansible-autorizarion-tokens-with-uri-module/21169 "2016-04-15T10:37:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_McCormack](https://avatars.discourse-cdn.com/v4/letter/j/8e8cbc/32.png) [@John\_McCormack](https://forum.ansible.com/u/John_McCormack)\
**Post date:** [April 15, 2016, 10:37am UTC](https://forum.ansible.com/t/ansible-autorizarion-tokens-with-uri-module/21169/1 "2016-04-15T10:37:31Z")

</div>

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](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](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.

---

<div class="post-metadata">

**Author:** ![Priyanka\_Reddy](https://avatars.discourse-cdn.com/v4/letter/p/3d9bf3/32.png) [@Priyanka\_Reddy](https://forum.ansible.com/u/Priyanka_Reddy)\
**Post date:** [August 26, 2016, 1:37am UTC](https://forum.ansible.com/t/ansible-autorizarion-tokens-with-uri-module/21169/2 "2016-08-26T01:37:16Z")

</div>

Hi WHERE YOU ABLE TO SOLVE THIS ISSUE?

I AM ALSO GETTING THE SAME ERROR?

---

<div class="post-metadata">

**Author:** ![Mohammed\_Reehan](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Mohammed\_Reehan](https://forum.ansible.com/u/Mohammed_Reehan)\
**Post date:** [July 18, 2022, 5:45pm UTC](https://forum.ansible.com/t/ansible-autorizarion-tokens-with-uri-module/21169/3 "2022-07-18T17:45:45Z")

</div>

Any update on this

---

<div class="post-metadata">

**Author:** ![dnmvisser](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@dnmvisser](https://forum.ansible.com/u/dnmvisser)\
**Post date:** [July 18, 2022, 7:52pm UTC](https://forum.ansible.com/t/ansible-autorizarion-tokens-with-uri-module/21169/4 "2022-07-18T19:52:56Z")

</div>

> 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.
