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.
This commit is contained in:
Damian Zaremba 2018-01-10 16:05:48 +01:00 committed by John R Barker
parent caf1b357aa
commit b88304f211
4 changed files with 20 additions and 2 deletions

View file

@ -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:

View file

@ -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')

View file

@ -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).

View file

@ -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).
"""