Uri module uses CONNECT instead of GET when going through a proxy and fails

250 views
Skip to first unread message

Benoit Tremblay

unread,
Mar 2, 2016, 12:19:26 PM3/2/16
to Ansible Project
I have a problem using uri when behind a proxy.  There is an exception in the python module.
This works well when not going through a proxy.  But fails when a proxy is set.

     - uri: url="http://www.google.com" dest="/tmp/tempfile"

fatal: [h39]: FAILED! => {"changed": false, "failed": true, "invocation": {"module_name": "uri"}, "module_stderr": "", "module_stdout": "Traceback (most recent call last):\r\n  File \"/root/.ansible/tmp/ansible-tmp-1456764961.49-135649813587956/uri\", line 2439, in <module>\r\n    main()\r\n  File \"/root/.ansible/tmp/ansible-tmp-1456764961.49-135649813587956/uri\", line 453, in main\r\n    resp, content, dest = uri(module, url, dest, user, password, body, body_format, method, dict_headers, redirects, socket_timeout, validate_certs)\r\n  File \"/root/.ansible/tmp/ansible-tmp-1456764961.49-135649813587956/uri\", line 340, in uri\r\n    resp, content = h.request(url, method=method, body=body, headers=headers)     \r\n  File \"/usr/local/lib/python2.7/dist-packages/httplib2/__init__.py\", line 1609, in request\r\n    (response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)\r\n  File \"/usr/local/lib/python2.7/dist-packages/httplib2/__init__.py\", line 1351, in _request\r\n    (response, content) = self._conn_request(conn, request_uri, method, body, headers)\r\n  File \"/usr/local/lib/python2.7/dist-packages/httplib2/__init__.py\", line 1272, in _conn_request\r\n    conn.connect()\r\n  File \"/usr/local/lib/python2.7/dist-packages/httplib2/__init__.py\", line 916, in connect\r\n    self.sock.connect((self.host, self.port) + sa[2:])\r\n  File \"/usr/local/lib/python2.7/dist-packages/httplib2/socks.py\", line 424, in connect\r\n    self.__negotiatehttp(destpair[0], destpair[1])\r\n  File \"/usr/local/lib/python2.7/dist-packages/httplib2/socks.py\", line 390, in __negotiatehttp\r\n    raise HTTPError((statuscode, statusline[2]))\r\nhttplib2.socks.HTTPError: (403, 'Forbidden')\r\n", "msg": "MODULE FAILURE", "parsed": false}


When listening on my proxy server, I realized that uri is trying to HTTP CONNECT to google, rather that using GET.  I compared with what wget or curl are doing and both of them are sending GET to the proxy.

Anyone has faced the same issue?

I am using version 2.0.0.1 of Ansible.
The remote node is running ubuntu 14.04.04

Matt Martz

unread,
Mar 2, 2016, 12:30:40 PM3/2/16
to ansible...@googlegroups.com
I think this is likely fixed in devel/2.1.

The `uri` module previously relied on httplib2.  That dependency has been removed and `uri` now utilizes the shared code from `ansible.module_utils.urls` that `get_url` and many other modules have been using for some time now.

--
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/c836f0b1-b919-4c67-84cd-cba507900062%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Matt Martz
@sivel
sivel.net

Benoit Tremblay

unread,
Mar 2, 2016, 4:31:46 PM3/2/16
to Ansible Project
Thanks!

Benoit
Reply all
Reply to author
Forward
0 new messages