Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for explicit proxy using ansible variable instead of environment variable #556

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/556-ansible_httpapi_explicit_proxy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- httpapi - New ansible_explicit_proxy variable for setting HTTP/HTTPS proxy with ansible variable instead of environment variable
18 changes: 18 additions & 0 deletions docs/ansible.netcommon.httpapi_connection.rst
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,24 @@ Parameters
<div>This option will have no effect on ansible-core&lt;2.14 but a warning will be emitted.</div>
</td>
</tr>
<tr>
<td colspan="1">
<div class="ansibleOptionAnchor" id="parameter-"></div>
<b>explicit_proxy</b>
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
<div style="font-size: small">
<span style="color: purple">string</span>
</div>
</td>
<td>
</td>
<td>
<div>var: ansible_httpapi_explicit_proxy</div>
</td>
<td>
<div>Define an explicit proxy for the connection. Will reset HTTPS_PROXY and HTTP_PROXY env variable</div>
</td>
</tr>
<tr>
<td colspan="1">
<div class="ansibleOptionAnchor" id="parameter-"></div>
Expand Down
12 changes: 12 additions & 0 deletions plugins/connection/httpapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"):
Expand Down