Ansible and Proxy Authentication

2,351 views
Skip to first unread message

titlei...@gmail.com

unread,
Feb 4, 2015, 12:37:18 PM2/4/15
to ansible...@googlegroups.com
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%40...@proxy.corporate.com
      https_proxy: http://user:p%40...@proxy.corporate.com
    remote_url: 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 <module>
    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 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

Dick Davies

unread,
Feb 4, 2015, 12:46:13 PM2/4/15
to ansible list
It's attempting to use the proxy by the looks of it, it just doesn't
like the user/pass you're providing.
> --
> 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/30669427-a370-428f-bdac-09c6307ed3fa%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

titlei...@gmail.com

unread,
Feb 4, 2015, 12:57:38 PM2/4/15
to ansible...@googlegroups.com, di...@hellooperator.net
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


On Wednesday, February 4, 2015 at 11:46:13 AM UTC-6, Dick Davies wrote:
It's attempting to use the proxy by the looks of it, it just doesn't
like the user/pass you're providing.


On 4 February 2015 at 17:37,  <titlei...@gmail.com> wrote:
> 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:

titlei...@gmail.com

unread,
Feb 4, 2015, 1:09:16 PM2/4/15
to ansible...@googlegroups.com, di...@hellooperator.net
Well that was the issue.  Just added some new credentials without the @ symbol in the password and it's working.

Thanks,
Jay

Dwarika Prasad

unread,
Feb 10, 2017, 3:01:13 PM2/10/17
to Ansible Project
Hi , 

It looks like it  was the username and password asked by your api hosted at https://my.remotesite.com/api/v1.
What if the proxy server http://user:p%40ss@proxy.corporate.com  asks  a user name and password from me. What will be the solution.

Please help.

Thanks,
Dwarika.

On Wednesday, 4 February 2015 17:37:18 UTC, titlei...@gmail.com wrote:
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:
Reply all
Reply to author
Forward
0 new messages