Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/ansible/ansible.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Karolak <nikaro@users.noreply.github.com>2022-08-03 19:56:22 +0300
committerGitHub <noreply@github.com>2022-08-03 19:56:22 +0300
commitbf1e031eb23256ffedddeba17cb3afa11476a6ae (patch)
tree83c7c67dfd2126c370dfdadf71a2ea5bead3d61a
parentfc82d215a67fed191d0320cbd1a55b4ac369116c (diff)
honor use_proxy parameter (#77312) (#78261)
* 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> (cherry picked from commit 1d9c68d27e10b6023d294d48e873ba4cdde46bbb) Co-authored-by: h4rr21 <juankchess13@hotmail.com>
-rw-r--r--changelogs/fragments/58632-uri-include_use_proxy.yaml2
-rw-r--r--lib/ansible/module_utils/urls.py7
-rw-r--r--lib/ansible/modules/uri.py1
-rw-r--r--test/integration/targets/uri/tasks/main.yml20
4 files changed, 28 insertions, 2 deletions
diff --git a/changelogs/fragments/58632-uri-include_use_proxy.yaml b/changelogs/fragments/58632-uri-include_use_proxy.yaml
new file mode 100644
index 00000000000..8c97c7c0da3
--- /dev/null
+++ b/changelogs/fragments/58632-uri-include_use_proxy.yaml
@@ -0,0 +1,2 @@
+bugfixes:
+ - uri - properly use uri parameter use_proxy (https://github.com/ansible/ansible/issues/58632)
diff --git a/lib/ansible/module_utils/urls.py b/lib/ansible/module_utils/urls.py
index f34c5368904..7e7ba225a39 100644
--- a/lib/ansible/module_utils/urls.py
+++ b/lib/ansible/module_utils/urls.py
@@ -1727,7 +1727,7 @@ def url_argument_spec():
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):
"""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 headers: A dict with the request headers.
: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 last_mod_time: Default: None
: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
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', '')
password = module.params.get('url_password', '')
http_agent = module.params.get('http_agent', 'ansible-httpget')
diff --git a/lib/ansible/modules/uri.py b/lib/ansible/modules/uri.py
index aed68ba51cd..58ef63ebb55 100644
--- a/lib/ansible/modules/uri.py
+++ b/lib/ansible/modules/uri.py
@@ -593,6 +593,7 @@ def uri(module, url, dest, body, body_format, method, headers, socket_timeout, c
resp, info = fetch_url(module, url, data=data, headers=headers,
method=method, timeout=socket_timeout, unix_socket=module.params['unix_socket'],
ca_path=ca_path, unredirected_headers=unredirected_headers,
+ use_proxy=module.params['use_proxy'],
**kwargs)
if src:
diff --git a/test/integration/targets/uri/tasks/main.yml b/test/integration/targets/uri/tasks/main.yml
index 1d560e5c400..a6ba646d0a9 100644
--- a/test/integration/targets/uri/tasks/main.yml
+++ b/test/integration/targets/uri/tasks/main.yml
@@ -301,6 +301,26 @@
that:
- '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
# 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