From b88304f2119ee4dc88b4463975fbeb9f4e61ebac Mon Sep 17 00:00:00 2001 From: Damian Zaremba Date: Wed, 10 Jan 2018 16:05:48 +0100 Subject: [PATCH] module_utils.(eos, nxos) - Support use_proxy argument (#30813) * eos - Support use_proxy argument Running ansible with a proxy set in the environment causes the eos module to attempt to connect to devices via the proxy. To prevent this behaviour the only way is to unset the proxy out of the environment, either by wrapping the ansible calls or doing it in a piece of code executed before connect, such as a vars_module (though this is very hacky). This change allows you to set `use_proxy: no` under the provider config. The default value is set to True, which mirrors the behaviour seen today. * nexos - Support use_proxy argument Running ansible with a proxy set in the environment causes the nexos module to attempt to connect to devices via the proxy. To prevent this behaviour the only way is to unset the proxy out of the environment, either by wrapping the ansible calls or doing it in a piece of code executed before connect, such as a vars_module (though this is very hacky). This change allows you to set `use_proxy: no` under the provider config. The default value is set to True, which mirrors the behaviour seen today. --- lib/ansible/module_utils/network/eos/eos.py | 4 +++- lib/ansible/module_utils/network/nxos/nxos.py | 4 +++- lib/ansible/utils/module_docs_fragments/eos.py | 7 +++++++ lib/ansible/utils/module_docs_fragments/nxos.py | 7 +++++++ 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/ansible/module_utils/network/eos/eos.py b/lib/ansible/module_utils/network/eos/eos.py index a548f13934..c9162f9d0a 100644 --- a/lib/ansible/module_utils/network/eos/eos.py +++ b/lib/ansible/module_utils/network/eos/eos.py @@ -50,6 +50,7 @@ eos_provider_spec = { 'auth_pass': dict(no_log=True, fallback=(env_fallback, ['ANSIBLE_NET_AUTH_PASS'])), 'use_ssl': dict(default=True, type='bool'), + 'use_proxy': dict(default=True, type='bool'), 'validate_certs': dict(default=True, type='bool'), 'timeout': dict(type='int'), @@ -292,10 +293,11 @@ class Eapi: headers = {'Content-Type': 'application/json-rpc'} timeout = self._module.params['timeout'] + use_proxy = self._module.params['provider']['use_proxy'] response, headers = fetch_url( self._module, self._url, data=data, headers=headers, - method='POST', timeout=timeout + method='POST', timeout=timeout, use_proxy=use_proxy ) if headers['status'] != 200: diff --git a/lib/ansible/module_utils/network/nxos/nxos.py b/lib/ansible/module_utils/network/nxos/nxos.py index 5c563097b7..ab9ac0b919 100644 --- a/lib/ansible/module_utils/network/nxos/nxos.py +++ b/lib/ansible/module_utils/network/nxos/nxos.py @@ -50,6 +50,7 @@ nxos_provider_spec = { 'ssh_keyfile': dict(fallback=(env_fallback, ['ANSIBLE_NET_SSH_KEYFILE'])), 'use_ssl': dict(type='bool'), + 'use_proxy': dict(default=True, type='bool'), 'validate_certs': dict(type='bool'), 'timeout': dict(type='int'), @@ -316,6 +317,7 @@ class Nxapi: headers = {'Content-Type': 'application/json'} result = list() timeout = self._module.params['timeout'] + use_proxy = self._module.params['provider']['use_proxy'] for req in requests: if self._nxapi_auth: @@ -323,7 +325,7 @@ class Nxapi: response, headers = fetch_url( self._module, self._url, data=req, headers=headers, - timeout=timeout, method='POST' + timeout=timeout, method='POST', use_proxy=use_proxy ) self._nxapi_auth = headers.get('set-cookie') diff --git a/lib/ansible/utils/module_docs_fragments/eos.py b/lib/ansible/utils/module_docs_fragments/eos.py index 93ec891c26..872f55f448 100644 --- a/lib/ansible/utils/module_docs_fragments/eos.py +++ b/lib/ansible/utils/module_docs_fragments/eos.py @@ -120,6 +120,13 @@ options: on personally controlled sites using self-signed certificates. If the transport argument is not eapi, this value is ignored. choices: ['yes', 'no'] + use_proxy: + description: + - If C(no), the environment variables C(http_proxy) and C(https_proxy) will be ignored. + default: 'yes' + choices: ['yes', 'no'] + version_added: "2.5" + notes: - For more information on using Ansible to manage Arista EOS devices see U(https://www.ansible.com/ansible-arista-networks). diff --git a/lib/ansible/utils/module_docs_fragments/nxos.py b/lib/ansible/utils/module_docs_fragments/nxos.py index 5e66fd2c2c..37b84375f1 100644 --- a/lib/ansible/utils/module_docs_fragments/nxos.py +++ b/lib/ansible/utils/module_docs_fragments/nxos.py @@ -95,6 +95,13 @@ options: met either by individual arguments or values in this dict. required: false default: null + use_proxy: + description: + - If C(no), the environment variables C(http_proxy) and C(https_proxy) will be ignored. + default: 'yes' + choices: ['yes', 'no'] + version_added: "2.5" + notes: - For more information on using Ansible to manage Cisco devices see U(https://www.ansible.com/ansible-cisco). """