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 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 f6bdf6949..d72298c6e 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"):