honor use_proxy parameter (#77312)

* honor use_proxy parameter
* fix uri test with "use_proxy: no"
* fix urls.py module

Co-authored-by: Carlos <Juan.Carlos.Cardenas.Viera@ibm.com>
pull/77484/head
h4rr21 3 years ago committed by GitHub
parent 5b44035983
commit 1d9c68d27e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,2 @@
bugfixes:
- uri - properly use uri parameter use_proxy (https://github.com/ansible/ansible/issues/58632)

@ -1727,7 +1727,7 @@ def url_argument_spec():
def fetch_url(module, url, data=None, headers=None, method=None, def fetch_url(module, url, data=None, headers=None, method=None,
use_proxy=True, force=False, last_mod_time=None, timeout=10, use_proxy=None, force=False, last_mod_time=None, timeout=10,
use_gssapi=False, unix_socket=None, ca_path=None, cookies=None, unredirected_headers=None): use_gssapi=False, unix_socket=None, ca_path=None, cookies=None, unredirected_headers=None):
"""Sends a request via HTTP(S) or FTP (needs the module as parameter) """Sends a request via HTTP(S) or FTP (needs the module as parameter)
@ -1737,7 +1737,7 @@ def fetch_url(module, url, data=None, headers=None, method=None,
:kwarg data: The data to be sent (in case of POST/PUT). :kwarg data: The data to be sent (in case of POST/PUT).
:kwarg headers: A dict with the request headers. :kwarg headers: A dict with the request headers.
:kwarg method: "POST", "PUT", etc. :kwarg method: "POST", "PUT", etc.
:kwarg boolean use_proxy: Default: True :kwarg use_proxy: (optional) whether or not to use proxy (Default: True)
:kwarg boolean force: If True: Do not get a cached copy (Default: False) :kwarg boolean force: If True: Do not get a cached copy (Default: False)
:kwarg last_mod_time: Default: None :kwarg last_mod_time: Default: None
:kwarg int timeout: Default: 10 :kwarg int timeout: Default: 10
@ -1776,6 +1776,9 @@ def fetch_url(module, url, data=None, headers=None, method=None,
# Get validate_certs from the module params # Get validate_certs from the module params
validate_certs = module.params.get('validate_certs', True) validate_certs = module.params.get('validate_certs', True)
if use_proxy is None:
use_proxy = module.params.get('use_proxy', True)
username = module.params.get('url_username', '') username = module.params.get('url_username', '')
password = module.params.get('url_password', '') password = module.params.get('url_password', '')
http_agent = module.params.get('http_agent', 'ansible-httpget') http_agent = module.params.get('http_agent', 'ansible-httpget')

@ -592,6 +592,7 @@ def uri(module, url, dest, body, body_format, method, headers, socket_timeout, c
resp, info = fetch_url(module, url, data=data, headers=headers, resp, info = fetch_url(module, url, data=data, headers=headers,
method=method, timeout=socket_timeout, unix_socket=module.params['unix_socket'], method=method, timeout=socket_timeout, unix_socket=module.params['unix_socket'],
ca_path=ca_path, unredirected_headers=unredirected_headers, ca_path=ca_path, unredirected_headers=unredirected_headers,
use_proxy=module.params['use_proxy'],
**kwargs) **kwargs)
if src: if src:

@ -301,6 +301,26 @@
that: that:
- 'result.allow.split(", ")|sort == ["GET", "HEAD", "OPTIONS"]' - 'result.allow.split(", ")|sort == ["GET", "HEAD", "OPTIONS"]'
- name: Testing support of https_proxy (with failure expected)
environment:
https_proxy: 'https://localhost:3456'
uri:
url: 'https://httpbin.org/get'
register: result
ignore_errors: true
- assert:
that:
- result is failed
- result.status == -1
- name: Testing use_proxy=no is honored
environment:
https_proxy: 'https://localhost:3456'
uri:
url: 'https://httpbin.org/get'
use_proxy: no
# Ubuntu12.04 doesn't have python-urllib3, this makes handling required dependencies a pain across all variations # Ubuntu12.04 doesn't have python-urllib3, this makes handling required dependencies a pain across all variations
# We'll use this to just skip 12.04 on those tests. We should be sufficiently covered with other OSes and versions # We'll use this to just skip 12.04 on those tests. We should be sufficiently covered with other OSes and versions
- name: Set fact if running on Ubuntu 12.04 - name: Set fact if running on Ubuntu 12.04

Loading…
Cancel
Save