# Ansible and Proxy Authentication

**URL:** <https://forum.ansible.com/t/ansible-and-proxy-authentication/17445>\
**Category:** Ansible Project\
**Created:** [February 4, 2015, 5:37pm UTC](https://forum.ansible.com/t/ansible-and-proxy-authentication/17445 "2015-02-04T17:37:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![titleistfour](https://avatars.discourse-cdn.com/v4/letter/t/65b543/32.png) [@titleistfour](https://forum.ansible.com/u/titleistfour)\
**Post date:** [February 4, 2015, 5:37pm UTC](https://forum.ansible.com/t/ansible-and-proxy-authentication/17445/1 "2015-02-04T17:37:17Z")

</div>

Hello,

I’m having some trouble getting proxy authentication to work in Ansible. I have a simple playbook I’m using to test with the `uri` module and a remote REST API service.

- hosts: localhost  
connection: localhost  
vars:  
proxy\_env:  
http\_proxy: [http://user:p%40ss@proxy.corporate.com](http://user:p%40ss@proxy.corporate.com)  
https\_proxy: [http://user:p%40ss@proxy.corporate.com](http://user:p%40ss@proxy.corporate.com)  
remote\_url: [https://my.remotesite.com/api/v1](https://my.remotesite.com/api/v1)  
api\_id: 1234  
api\_key: 1234-5678  
tasks:
- debug: msg=“Testing {{ proxy\_env }}”
- uri: url={{ remote\_url }}  
method=POST body=“api\_id={{ api\_id }}&api\_key={{ api\_key }}”  
environment: proxy\_env

And the result is always

failed: [localhost] =\> {“failed”: true, “parsed”: false}  
Traceback (most recent call last):  
File “/home/user/.ansible/tmp/ansible-tmp-1423071257.11-151456645393471/uri”, line 2011, in   
main()  
File “/home/user/.ansible/tmp/ansible-tmp-1423071257.11-151456645393471/uri”, line 403, in main  
resp, content, dest = uri(module, url, dest, user, password, body, method, dict\_headers, redirects, socket\_timeout)  
File “/home/user/.ansible/tmp/ansible-tmp-1423071257.11-151456645393471/uri”, line 302, in uri  
resp, content = h.request(url, method=method, body=body, headers=headers)  
File “/usr/lib/python2.6/site-packages/httplib2/ **init**.py”, line 1605, in request  
(response, content) = self.\_request(conn, authority, uri, request\_uri, method, body, headers, redirections, cachekey)  
File “/usr/lib/python2.6/site-packages/httplib2/ **init**.py”, line 1353, in \_request  
(response, content) = self.\_conn\_request(conn, request\_uri, method, body, headers)  
File “/usr/lib/python2.6/site-packages/httplib2/ **init**.py”, line 1289, in \_conn\_request  
conn.connect()  
File “/usr/lib/python2.6/site-packages/httplib2/ **init**.py”, line 1018, in connect  
sock.connect((self.host, self.port))  
File “/usr/lib/python2.6/site-packages/httplib2/socks.py”, line 424, in connect  
self.\_\_negotiatehttp(destpair[0], destpair[1])  
File “/usr/lib/python2.6/site-packages/httplib2/socks.py”, line 390, in \_\_negotiatehttp  
raise HTTPError((statuscode, statusline[2]))  
httplib2.socks.HTTPError: (407, ‘Proxy Authentication Required’)

The directions at [http://docs.ansible.com/playbooks\_environment.html](http://docs.ansible.com/playbooks_environment.html) are quite clear, so I’m not sure what is going on.

Have I defined something in my playbook incorrectly?

Does the `uri` module not respect proxy environment settings?

Thanks,  
Jay

---

<div class="post-metadata">

**Author:** ![Dick\_Davies](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@Dick\_Davies](https://forum.ansible.com/u/Dick_Davies)\
**Post date:** [February 4, 2015, 5:46pm UTC](https://forum.ansible.com/t/ansible-and-proxy-authentication/17445/2 "2015-02-04T17:46:10Z")

</div>

It's attempting to use the proxy by the looks of it, it just doesn't  
like the user/pass you're providing.

---

<div class="post-metadata">

**Author:** ![titleistfour](https://avatars.discourse-cdn.com/v4/letter/t/65b543/32.png) [@titleistfour](https://forum.ansible.com/u/titleistfour)\
**Post date:** [February 4, 2015, 5:57pm UTC](https://forum.ansible.com/t/ansible-and-proxy-authentication/17445/3 "2015-02-04T17:57:38Z")

</div>

Thanks for the response. I’m wondering if it’s the password. It has an @ symbol in it. I’ve tried encoding that with %40, but that still doesn’t work either. Any suggestions on how to get around that issue?

Thanks,  
Jay

---

<div class="post-metadata">

**Author:** ![titleistfour](https://avatars.discourse-cdn.com/v4/letter/t/65b543/32.png) [@titleistfour](https://forum.ansible.com/u/titleistfour)\
**Post date:** [February 4, 2015, 6:09pm UTC](https://forum.ansible.com/t/ansible-and-proxy-authentication/17445/4 "2015-02-04T18:09:16Z")

</div>

Well that was the issue. Just added some new credentials without the @ symbol in the password and it’s working.

Thanks,  
Jay

---

<div class="post-metadata">

**Author:** ![Dwarika\_Prasad](https://avatars.discourse-cdn.com/v4/letter/d/cdc98d/32.png) [@Dwarika\_Prasad](https://forum.ansible.com/u/Dwarika_Prasad)\
**Post date:** [February 10, 2017, 5:03pm UTC](https://forum.ansible.com/t/ansible-and-proxy-authentication/17445/5 "2017-02-10T17:03:05Z")

</div>

Hi ,

It looks like it was the username and password asked by your api hosted at [https://my.remotesite.com/api/v1](https://www.google.com/url?q=https%3A%2F%2Fmy.remotesite.com%2Fapi%2Fv1&sa=D&sntz=1&usg=AFQjCNGAbJwEagbaQ0eIZhBGM2G-kQujLQ).  
What if the proxy server [http://user:p%40ss@proxy.corporate.com](http://user:p%40ss@proxy.corporate.com/) asks a user name and password from me. What will be the solution.

Please help.

Thanks,  
Dwarika.
