diff --git a/lib/ansible/module_utils/eos.py b/lib/ansible/module_utils/eos.py index 21f8e05dc44..a0ae4434a69 100644 --- a/lib/ansible/module_utils/eos.py +++ b/lib/ansible/module_utils/eos.py @@ -40,7 +40,7 @@ _DEVICE_CONNECTION = None eos_argument_spec = { 'host': dict(), - 'port': dict(type='int', default=443), + 'port': dict(type='int'), 'username': dict(fallback=(env_fallback, ['ANSIBLE_NET_USERNAME'])), 'password': dict(fallback=(env_fallback, ['ANSIBLE_NET_PASSWORD']), no_log=True), 'ssh_keyfile': dict(fallback=(env_fallback, ['ANSIBLE_NET_SSH_KEYFILE']), type='path'), @@ -49,14 +49,21 @@ eos_argument_spec = { 'authorize': dict(fallback=(env_fallback, ['ANSIBLE_NET_AUTHORIZE']), type='bool'), 'auth_pass': dict(no_log=True, fallback=(env_fallback, ['ANSIBLE_NET_AUTH_PASS'])), - 'use_ssl': dict(type='bool', default=True), - 'validate_certs': dict(type='bool', default=True), + 'use_ssl': dict(type='bool'), + 'validate_certs': dict(type='bool'), 'timeout': dict(type='int'), 'provider': dict(type='dict'), 'transport': dict(choices=['cli', 'eapi']) } +# Add argument's default value here +ARGS_DEFAULT_VALUE = { + 'port': 443, + 'use_ssl': True, + 'validate_certs': True +} + def check_args(module, warnings): provider = module.params['provider'] or {} for key in eos_argument_spec: @@ -64,6 +71,13 @@ def check_args(module, warnings): warnings.append('argument %s has been deprecated and will be ' 'removed in a future version' % key) + # set argument's default value if not provided in input + # This is done to avoid unwanted argument deprecation warning + # in case argument is not given as input (outside provider). + for key in ARGS_DEFAULT_VALUE: + if not module.params.get(key, None): + module.params[key] = ARGS_DEFAULT_VALUE[key] + if provider: for param in ('auth_pass', 'password'): if provider.get(param): diff --git a/lib/ansible/module_utils/junos.py b/lib/ansible/module_utils/junos.py index bea6e65a492..6ba03018933 100644 --- a/lib/ansible/module_utils/junos.py +++ b/lib/ansible/module_utils/junos.py @@ -36,11 +36,16 @@ junos_argument_spec = { 'username': dict(fallback=(env_fallback, ['ANSIBLE_NET_USERNAME'])), 'password': dict(fallback=(env_fallback, ['ANSIBLE_NET_PASSWORD']), no_log=True), 'ssh_keyfile': dict(fallback=(env_fallback, ['ANSIBLE_NET_SSH_KEYFILE']), type='path'), - 'timeout': dict(type='int', default=10), + 'timeout': dict(type='int'), 'provider': dict(type='dict'), 'transport': dict() } +# Add argument's default value here +ARGS_DEFAULT_VALUE = { + 'timeout': 10 +} + def check_args(module, warnings): provider = module.params['provider'] or {} for key in junos_argument_spec: @@ -48,6 +53,13 @@ def check_args(module, warnings): warnings.append('argument %s has been deprecated and will be ' 'removed in a future version' % key) + # set argument's default value if not provided in input + # This is done to avoid unwanted argument deprecation warning + # in case argument is not given as input (outside provider). + for key in ARGS_DEFAULT_VALUE: + if not module.params.get(key, None): + module.params[key] = ARGS_DEFAULT_VALUE[key] + if provider: for param in ('password',): if provider.get(param): diff --git a/lib/ansible/module_utils/nxos.py b/lib/ansible/module_utils/nxos.py index 8bea8f35971..b13d50574a6 100644 --- a/lib/ansible/module_utils/nxos.py +++ b/lib/ansible/module_utils/nxos.py @@ -54,6 +54,11 @@ nxos_argument_spec = { 'transport': dict(choices=['cli', 'nxapi']) } +# Add argument's default value here +ARGS_DEFAULT_VALUE = { + 'timeout': 10 +} + def check_args(module, warnings): provider = module.params['provider'] or {} for key in nxos_argument_spec: @@ -61,6 +66,13 @@ def check_args(module, warnings): warnings.append('argument %s has been deprecated and will be ' 'removed in a future version' % key) + # set argument's default value if not provided in input + # This is done to avoid unwanted argument deprecation warning + # in case argument is not given as input (outside provider). + for key in ARGS_DEFAULT_VALUE: + if not module.params.get(key, None): + module.params[key] = ARGS_DEFAULT_VALUE[key] + if provider: for param in ('password',): if provider.get(param): @@ -240,7 +252,7 @@ class Nxapi: headers = {'Content-Type': 'application/json'} result = list() - timeout = self._module.params['timeout'] or 10 + timeout = self._module.params['timeout'] for req in requests: if self._nxapi_auth: diff --git a/lib/ansible/modules/network/eos/eos_facts.py b/lib/ansible/modules/network/eos/eos_facts.py index cd81cf91abb..92b8887058c 100644 --- a/lib/ansible/modules/network/eos/eos_facts.py +++ b/lib/ansible/modules/network/eos/eos_facts.py @@ -375,7 +375,7 @@ def main(): key = 'ansible_net_%s' % key ansible_facts[key] = value - module.exit_json(ansible_facts=ansible_facts) + module.exit_json(ansible_facts=ansible_facts, warnings=warnings) if __name__ == '__main__':