From 36cdc6bec682fac4cfee0ef65c27fc870db6b43b Mon Sep 17 00:00:00 2001 From: yodzeb Date: Fri, 23 Jun 2023 10:14:21 +0200 Subject: [PATCH 1/3] Update httpapi.py Support for an explicit proxy via ansible variable. https://github.com/fortinet-ansible-dev/ansible-galaxy-fortios-collection/issues/240 --- plugins/connection/httpapi.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/plugins/connection/httpapi.py b/plugins/connection/httpapi.py index f6bdf6949..6fda4e1bc 100644 --- a/plugins/connection/httpapi.py +++ b/plugins/connection/httpapi.py @@ -101,6 +101,12 @@ default: true vars: - name: ansible_httpapi_use_proxy + explicit_proxy: + type: string + description: + - Define an explicit proxy for the connection. Will reset HTTPS_PROXY and HTTP_PROXY env variable + vars: + - name: ansible_httpapi_explicit_proxy ciphers: description: - SSL/TLS Ciphers to use for requests @@ -156,6 +162,7 @@ """ from io import BytesIO +from os import environ from ansible.errors import AnsibleConnectionFailure from ansible.module_utils._text import to_bytes @@ -284,6 +291,11 @@ def send(self, path, data, retries=None, **kwargs): ) url_kwargs.update(kwargs) + explicit_proxy = self.get_option("explicit_proxy") + if explicit_proxy and explicit_proxy != "": + environ['HTTPS_PROXY'] = explicit_proxy + environ['HTTP_PROXY'] = explicit_proxy + ciphers = self.get_option("ciphers") if ciphers: if Version(ANSIBLE_CORE_VERSION) >= Version("2.14.0"): From 2989699c90a32f2cd31c73b180fda1e94071cd11 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 23 Jun 2023 08:29:41 +0000 Subject: [PATCH 2/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- docs/ansible.netcommon.httpapi_connection.rst | 18 ++++++++++++++++++ plugins/connection/httpapi.py | 4 ++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/docs/ansible.netcommon.httpapi_connection.rst b/docs/ansible.netcommon.httpapi_connection.rst index 5131703c8..6962f25b1 100644 --- a/docs/ansible.netcommon.httpapi_connection.rst +++ b/docs/ansible.netcommon.httpapi_connection.rst @@ -105,6 +105,24 @@ Parameters
This option will have no effect on ansible-core<2.14 but a warning will be emitted.
+ + +
+ explicit_proxy + +
+ string +
+ + + + +
var: ansible_httpapi_explicit_proxy
+ + +
Define an explicit proxy for the connection. Will reset HTTPS_PROXY and HTTP_PROXY env variable
+ +
diff --git a/plugins/connection/httpapi.py b/plugins/connection/httpapi.py index 6fda4e1bc..d72298c6e 100644 --- a/plugins/connection/httpapi.py +++ b/plugins/connection/httpapi.py @@ -293,8 +293,8 @@ def send(self, path, data, retries=None, **kwargs): explicit_proxy = self.get_option("explicit_proxy") if explicit_proxy and explicit_proxy != "": - environ['HTTPS_PROXY'] = explicit_proxy - environ['HTTP_PROXY'] = explicit_proxy + environ["HTTPS_PROXY"] = explicit_proxy + environ["HTTP_PROXY"] = explicit_proxy ciphers = self.get_option("ciphers") if ciphers: From 6bfd7334012e2876c9d17d4686b1c4a7b3608766 Mon Sep 17 00:00:00 2001 From: yodzeb Date: Fri, 23 Jun 2023 11:58:50 +0200 Subject: [PATCH 3/3] Create 556-ansible_httpapi_explicit_proxy.yml --- changelogs/fragments/556-ansible_httpapi_explicit_proxy.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 changelogs/fragments/556-ansible_httpapi_explicit_proxy.yml diff --git a/changelogs/fragments/556-ansible_httpapi_explicit_proxy.yml b/changelogs/fragments/556-ansible_httpapi_explicit_proxy.yml new file mode 100644 index 000000000..9abe4a62d --- /dev/null +++ b/changelogs/fragments/556-ansible_httpapi_explicit_proxy.yml @@ -0,0 +1,2 @@ +minor_changes: + - httpapi - New ansible_explicit_proxy variable for setting HTTP/HTTPS proxy with ansible variable instead of environment variable