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:
parent
caf1b357aa
commit
b88304f211
4 changed files with 20 additions and 2 deletions
|
@ -50,6 +50,7 @@ eos_provider_spec = {
|
||||||
'auth_pass': dict(no_log=True, fallback=(env_fallback, ['ANSIBLE_NET_AUTH_PASS'])),
|
'auth_pass': dict(no_log=True, fallback=(env_fallback, ['ANSIBLE_NET_AUTH_PASS'])),
|
||||||
|
|
||||||
'use_ssl': dict(default=True, type='bool'),
|
'use_ssl': dict(default=True, type='bool'),
|
||||||
|
'use_proxy': dict(default=True, type='bool'),
|
||||||
'validate_certs': dict(default=True, type='bool'),
|
'validate_certs': dict(default=True, type='bool'),
|
||||||
'timeout': dict(type='int'),
|
'timeout': dict(type='int'),
|
||||||
|
|
||||||
|
@ -292,10 +293,11 @@ class Eapi:
|
||||||
|
|
||||||
headers = {'Content-Type': 'application/json-rpc'}
|
headers = {'Content-Type': 'application/json-rpc'}
|
||||||
timeout = self._module.params['timeout']
|
timeout = self._module.params['timeout']
|
||||||
|
use_proxy = self._module.params['provider']['use_proxy']
|
||||||
|
|
||||||
response, headers = fetch_url(
|
response, headers = fetch_url(
|
||||||
self._module, self._url, data=data, headers=headers,
|
self._module, self._url, data=data, headers=headers,
|
||||||
method='POST', timeout=timeout
|
method='POST', timeout=timeout, use_proxy=use_proxy
|
||||||
)
|
)
|
||||||
|
|
||||||
if headers['status'] != 200:
|
if headers['status'] != 200:
|
||||||
|
|
|
@ -50,6 +50,7 @@ nxos_provider_spec = {
|
||||||
'ssh_keyfile': dict(fallback=(env_fallback, ['ANSIBLE_NET_SSH_KEYFILE'])),
|
'ssh_keyfile': dict(fallback=(env_fallback, ['ANSIBLE_NET_SSH_KEYFILE'])),
|
||||||
|
|
||||||
'use_ssl': dict(type='bool'),
|
'use_ssl': dict(type='bool'),
|
||||||
|
'use_proxy': dict(default=True, type='bool'),
|
||||||
'validate_certs': dict(type='bool'),
|
'validate_certs': dict(type='bool'),
|
||||||
|
|
||||||
'timeout': dict(type='int'),
|
'timeout': dict(type='int'),
|
||||||
|
@ -316,6 +317,7 @@ class Nxapi:
|
||||||
headers = {'Content-Type': 'application/json'}
|
headers = {'Content-Type': 'application/json'}
|
||||||
result = list()
|
result = list()
|
||||||
timeout = self._module.params['timeout']
|
timeout = self._module.params['timeout']
|
||||||
|
use_proxy = self._module.params['provider']['use_proxy']
|
||||||
|
|
||||||
for req in requests:
|
for req in requests:
|
||||||
if self._nxapi_auth:
|
if self._nxapi_auth:
|
||||||
|
@ -323,7 +325,7 @@ class Nxapi:
|
||||||
|
|
||||||
response, headers = fetch_url(
|
response, headers = fetch_url(
|
||||||
self._module, self._url, data=req, headers=headers,
|
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')
|
self._nxapi_auth = headers.get('set-cookie')
|
||||||
|
|
||||||
|
|
|
@ -120,6 +120,13 @@ options:
|
||||||
on personally controlled sites using self-signed certificates. If the transport
|
on personally controlled sites using self-signed certificates. If the transport
|
||||||
argument is not eapi, this value is ignored.
|
argument is not eapi, this value is ignored.
|
||||||
choices: ['yes', 'no']
|
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:
|
notes:
|
||||||
- For more information on using Ansible to manage Arista EOS devices see U(https://www.ansible.com/ansible-arista-networks).
|
- For more information on using Ansible to manage Arista EOS devices see U(https://www.ansible.com/ansible-arista-networks).
|
||||||
|
|
||||||
|
|
|
@ -95,6 +95,13 @@ options:
|
||||||
met either by individual arguments or values in this dict.
|
met either by individual arguments or values in this dict.
|
||||||
required: false
|
required: false
|
||||||
default: null
|
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:
|
notes:
|
||||||
- For more information on using Ansible to manage Cisco devices see U(https://www.ansible.com/ansible-cisco).
|
- For more information on using Ansible to manage Cisco devices see U(https://www.ansible.com/ansible-cisco).
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in a new issue