Removed in 29 (#63680)

* Eh, 2.10 is close enough

* drop top-level authorize

* Remove from documentation

* Remove load_params

* Centralize this junos thing

* Fixup user modules

* I'm 95% sure this did not do what it was supposed to

* nxos_hsrp: I don't think this is an actual module parameter

* Try to fix junos_package tests

* Move local params to provider

* Promote 'timeout' to a real parameter for eos_eapi

* Don't assume provider exists?

* move another timeout

* Provider now always has auth_pass

* Fix junos tests to avoid NameErrors
pull/63928/head
Nathaniel Case 5 years ago committed by GitHub
parent 553767ef50
commit 7f5d1ab2b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -430,12 +430,10 @@ def validate_prefix(prefix):
def load_provider(spec, args): def load_provider(spec, args):
provider = args.get('provider', {}) provider = args.get('provider') or {}
for key, value in iteritems(spec): for key, value in iteritems(spec):
if key not in provider: if key not in provider:
if key in args: if 'fallback' in value:
provider[key] = args[key]
elif 'fallback' in value:
provider[key] = _fallback(value['fallback']) provider[key] = _fallback(value['fallback'])
elif 'default' in value: elif 'default' in value:
provider[key] = value['default'] provider[key] = value['default']

@ -36,7 +36,6 @@ from ansible.module_utils.basic import env_fallback
from ansible.module_utils.connection import Connection, ConnectionError from ansible.module_utils.connection import Connection, ConnectionError
from ansible.module_utils.network.common.config import NetworkConfig, dumps from ansible.module_utils.network.common.config import NetworkConfig, dumps
from ansible.module_utils.network.common.utils import to_list, ComplexList from ansible.module_utils.network.common.utils import to_list, ComplexList
from ansible.module_utils.six import iteritems
from ansible.module_utils.urls import fetch_url from ansible.module_utils.urls import fetch_url
_DEVICE_CONNECTION = None _DEVICE_CONNECTION = None
@ -61,41 +60,15 @@ eos_provider_spec = {
eos_argument_spec = { eos_argument_spec = {
'provider': dict(type='dict', options=eos_provider_spec), 'provider': dict(type='dict', options=eos_provider_spec),
} }
eos_top_spec = {
'host': dict(removed_in_version=2.9),
'port': dict(removed_in_version=2.9, type='int'),
'username': dict(removed_in_version=2.9),
'password': dict(removed_in_version=2.9, no_log=True),
'ssh_keyfile': dict(removed_in_version=2.9, type='path'),
'authorize': dict(fallback=(env_fallback, ['ANSIBLE_NET_AUTHORIZE']), type='bool'),
'auth_pass': dict(removed_in_version=2.9, no_log=True),
'use_ssl': dict(removed_in_version=2.9, type='bool'),
'validate_certs': dict(removed_in_version=2.9, type='bool'),
'timeout': dict(removed_in_version=2.9, type='int'),
'transport': dict(removed_in_version=2.9, choices=['cli', 'eapi'])
}
eos_argument_spec.update(eos_top_spec)
def get_provider_argspec(): def get_provider_argspec():
return eos_provider_spec return eos_provider_spec
def load_params(module):
provider = module.params.get('provider') or dict()
for key, value in iteritems(provider):
if key in eos_argument_spec:
if module.params.get(key) is None and value is not None:
module.params[key] = value
def get_connection(module): def get_connection(module):
global _DEVICE_CONNECTION global _DEVICE_CONNECTION
if not _DEVICE_CONNECTION: if not _DEVICE_CONNECTION:
load_params(module)
if is_local_eapi(module): if is_local_eapi(module):
conn = LocalEapi(module) conn = LocalEapi(module)
else: else:
@ -210,23 +183,24 @@ class LocalEapi:
self._session_support = None self._session_support = None
self._device_configs = {} self._device_configs = {}
host = module.params['provider']['host'] provider = module.params.get("provider") or {}
port = module.params['provider']['port'] host = provider.get('host')
port = provider.get('port')
self._module.params['url_username'] = self._module.params['username'] self._module.params['url_username'] = provider.get('username')
self._module.params['url_password'] = self._module.params['password'] self._module.params['url_password'] = provider.get('password')
if module.params['provider']['use_ssl']: if provider.get('use_ssl'):
proto = 'https' proto = 'https'
else: else:
proto = 'http' proto = 'http'
module.params['validate_certs'] = module.params['provider']['validate_certs'] module.params['validate_certs'] = provider.get('validate_certs')
self._url = '%s://%s:%s/command-api' % (proto, host, port) self._url = '%s://%s:%s/command-api' % (proto, host, port)
if module.params['auth_pass']: if provider.get("auth_pass"):
self._enable = {'cmd': 'enable', 'input': module.params['auth_pass']} self._enable = {'cmd': 'enable', 'input': provider.get('auth_pass')}
else: else:
self._enable = 'enable' self._enable = 'enable'
@ -251,7 +225,7 @@ class LocalEapi:
data = self._module.jsonify(body) data = self._module.jsonify(body)
headers = {'Content-Type': 'application/json-rpc'} headers = {'Content-Type': 'application/json-rpc'}
timeout = self._module.params['timeout'] timeout = self._module.params['provider']['timeout']
use_proxy = self._module.params['provider']['use_proxy'] use_proxy = self._module.params['provider']['use_proxy']
response, headers = fetch_url( response, headers = fetch_url(
@ -595,12 +569,10 @@ def is_json(cmd):
def is_local_eapi(module): def is_local_eapi(module):
transports = []
transports.append(module.params.get('transport', ""))
provider = module.params.get('provider') provider = module.params.get('provider')
if provider: if provider:
transports.append(provider.get('transport', "")) return provider.get('transport') == 'eapi'
return 'eapi' in transports return False
def to_command(module, commands): def to_command(module, commands):

@ -48,18 +48,6 @@ ios_argument_spec = {
'provider': dict(type='dict', options=ios_provider_spec), 'provider': dict(type='dict', options=ios_provider_spec),
} }
ios_top_spec = {
'host': dict(removed_in_version=2.9),
'port': dict(removed_in_version=2.9, type='int'),
'username': dict(removed_in_version=2.9),
'password': dict(removed_in_version=2.9, no_log=True),
'ssh_keyfile': dict(removed_in_version=2.9, type='path'),
'authorize': dict(fallback=(env_fallback, ['ANSIBLE_NET_AUTHORIZE']), type='bool'),
'auth_pass': dict(removed_in_version=2.9, no_log=True),
'timeout': dict(removed_in_version=2.9, type='int')
}
ios_argument_spec.update(ios_top_spec)
def get_provider_argspec(): def get_provider_argspec():
return ios_provider_spec return ios_provider_spec

@ -90,16 +90,6 @@ command_spec = {
'answer': dict(default=None) 'answer': dict(default=None)
} }
iosxr_top_spec = {
'host': dict(removed_in_version=2.9),
'port': dict(removed_in_version=2.9, type='int'),
'username': dict(removed_in_version=2.9),
'password': dict(removed_in_version=2.9, no_log=True),
'ssh_keyfile': dict(removed_in_version=2.9, type='path'),
'timeout': dict(removed_in_version=2.9, type='int'),
}
iosxr_argument_spec.update(iosxr_top_spec)
CONFIG_MISPLACED_CHILDREN = [ CONFIG_MISPLACED_CHILDREN = [
re.compile(r'^end-\s*(.+)$') re.compile(r'^end-\s*(.+)$')
] ]

@ -10,7 +10,8 @@ calls the appropriate facts gathering function
""" """
from ansible.module_utils.network.common.facts.facts import FactsBase from ansible.module_utils.network.common.facts.facts import FactsBase
from ansible.module_utils.network.junos.facts.legacy.base import Default, Hardware, Config, Interfaces, OFacts, HAS_PYEZ from ansible.module_utils.network.junos.junos import HAS_PYEZ
from ansible.module_utils.network.junos.facts.legacy.base import Default, Hardware, Config, Interfaces, OFacts
from ansible.module_utils.network.junos.facts.interfaces.interfaces import InterfacesFacts from ansible.module_utils.network.junos.facts.interfaces.interfaces import InterfacesFacts
from ansible.module_utils.network.junos.facts.lacp.lacp import LacpFacts from ansible.module_utils.network.junos.facts.lacp.lacp import LacpFacts
from ansible.module_utils.network.junos.facts.lacp_interfaces.lacp_interfaces import Lacp_interfacesFacts from ansible.module_utils.network.junos.facts.lacp_interfaces.lacp_interfaces import Lacp_interfacesFacts

@ -11,8 +11,8 @@ based on the configuration.
import platform import platform
from ansible.module_utils.network.common.netconf import exec_rpc from ansible.module_utils.network.common.netconf import exec_rpc
from ansible.module_utils.network.junos.junos import get_param, tostring from ansible.module_utils.network.junos.junos import tostring
from ansible.module_utils.network.junos.junos import get_configuration, get_capabilities from ansible.module_utils.network.junos.junos import get_configuration, get_capabilities, get_device
from ansible.module_utils._text import to_text from ansible.module_utils._text import to_text
@ -21,13 +21,6 @@ try:
except ImportError: except ImportError:
from xml.etree.ElementTree import Element, SubElement from xml.etree.ElementTree import Element, SubElement
try:
from jnpr.junos import Device
from jnpr.junos.exception import ConnectError
HAS_PYEZ = True
except ImportError:
HAS_PYEZ = False
class FactsBase(object): class FactsBase(object):
@ -184,33 +177,9 @@ class Interfaces(FactsBase):
class OFacts(FactsBase): class OFacts(FactsBase):
def _connect(self, module):
host = get_param(module, 'host')
kwargs = {
'port': get_param(module, 'port') or 830,
'user': get_param(module, 'username')
}
if get_param(module, 'password'):
kwargs['passwd'] = get_param(module, 'password')
if get_param(module, 'ssh_keyfile'):
kwargs['ssh_private_key_file'] = get_param(module, 'ssh_keyfile')
kwargs['gather_facts'] = False
try:
device = Device(host, **kwargs)
device.open()
device.timeout = get_param(module, 'timeout') or 10
except ConnectError as exc:
module.fail_json('unable to connect to %s: %s' % (host, to_text(exc)))
return device
def populate(self): def populate(self):
device = self._connect(self.module) device = get_device(self.module)
facts = dict(device.facts) facts = dict(device.facts)
if '2RE' in facts: if '2RE' in facts:

@ -33,6 +33,13 @@ except ImportError:
from xml.etree.ElementTree import Element, SubElement, tostring as xml_to_string from xml.etree.ElementTree import Element, SubElement, tostring as xml_to_string
HAS_LXML = False HAS_LXML = False
try:
from jnpr.junos import Device
from jnpr.junos.exception import ConnectError
HAS_PYEZ = True
except ImportError:
HAS_PYEZ = False
ACTIONS = frozenset(['merge', 'override', 'replace', 'update', 'set']) ACTIONS = frozenset(['merge', 'override', 'replace', 'update', 'set'])
JSON_ACTIONS = frozenset(['merge', 'override', 'update']) JSON_ACTIONS = frozenset(['merge', 'override', 'update'])
FORMATS = frozenset(['xml', 'text', 'json']) FORMATS = frozenset(['xml', 'text', 'json'])
@ -50,16 +57,6 @@ junos_provider_spec = {
junos_argument_spec = { junos_argument_spec = {
'provider': dict(type='dict', options=junos_provider_spec), 'provider': dict(type='dict', options=junos_provider_spec),
} }
junos_top_spec = {
'host': dict(removed_in_version=2.9),
'port': dict(removed_in_version=2.9, type='int'),
'username': dict(removed_in_version=2.9),
'password': dict(removed_in_version=2.9, no_log=True),
'ssh_keyfile': dict(removed_in_version=2.9, type='path'),
'timeout': dict(removed_in_version=2.9, type='int'),
'transport': dict(removed_in_version=2.9)
}
junos_argument_spec.update(junos_top_spec)
def tostring(element, encoding='UTF-8'): def tostring(element, encoding='UTF-8'):
@ -101,6 +98,33 @@ def get_capabilities(module):
return module._junos_capabilities return module._junos_capabilities
def get_device(module):
provider = module.params.get("provider") or {}
host = provider.get('host')
kwargs = {
'port': provider.get('port') or 830,
'user': provider.get('username')
}
if 'password' in provider:
kwargs['passwd'] = provider.get('password')
if 'ssh_keyfile' in provider:
kwargs['ssh_private_key_file'] = provider.get('ssh_keyfile')
kwargs['gather_facts'] = False
try:
device = Device(host, **kwargs)
device.open()
device.timeout = provider.get('timeout') or 10
except ConnectError as exc:
module.fail_json('unable to connect to %s: %s' % (host, to_text(exc)))
return device
def is_netconf(module): def is_netconf(module):
capabilities = get_capabilities(module) capabilities = get_capabilities(module)
return True if capabilities.get('network_api') == 'netconf' else False return True if capabilities.get('network_api') == 'netconf' else False
@ -252,16 +276,6 @@ def load_config(module, candidate, warnings, action='merge', format='xml'):
return get_diff(module) return get_diff(module)
def get_param(module, key):
if module.params.get(key):
value = module.params[key]
elif module.params.get('provider'):
value = module.params['provider'].get(key)
else:
value = None
return value
def map_params_to_obj(module, param_to_xpath_map, param=None): def map_params_to_obj(module, param_to_xpath_map, param=None):
""" """
Creates a new dictionary with key as xpath corresponding Creates a new dictionary with key as xpath corresponding

@ -83,42 +83,15 @@ nxos_provider_spec = {
nxos_argument_spec = { nxos_argument_spec = {
'provider': dict(type='dict', options=nxos_provider_spec), 'provider': dict(type='dict', options=nxos_provider_spec),
} }
nxos_top_spec = {
'host': dict(type='str', removed_in_version=2.9),
'port': dict(type='int', removed_in_version=2.9),
'username': dict(type='str', removed_in_version=2.9),
'password': dict(type='str', no_log=True, removed_in_version=2.9),
'ssh_keyfile': dict(type='str', removed_in_version=2.9),
'authorize': dict(type='bool', fallback=(env_fallback, ['ANSIBLE_NET_AUTHORIZE'])),
'auth_pass': dict(type='str', no_log=True, removed_in_version=2.9),
'use_ssl': dict(type='bool', removed_in_version=2.9),
'validate_certs': dict(type='bool', removed_in_version=2.9),
'timeout': dict(type='int', removed_in_version=2.9),
'transport': dict(type='str', choices=['cli', 'nxapi'], removed_in_version=2.9)
}
nxos_argument_spec.update(nxos_top_spec)
def get_provider_argspec(): def get_provider_argspec():
return nxos_provider_spec return nxos_provider_spec
def load_params(module):
provider = module.params.get('provider') or dict()
for key, value in iteritems(provider):
if key in nxos_provider_spec:
if module.params.get(key) is None and value is not None:
module.params[key] = value
def get_connection(module): def get_connection(module):
global _DEVICE_CONNECTION global _DEVICE_CONNECTION
if not _DEVICE_CONNECTION: if not _DEVICE_CONNECTION:
load_params(module)
if is_local_nxapi(module): if is_local_nxapi(module):
conn = LocalNxapi(module) conn = LocalNxapi(module)
else: else:
@ -278,13 +251,14 @@ class LocalNxapi:
self._device_configs = {} self._device_configs = {}
self._module_context = {} self._module_context = {}
self._module.params['url_username'] = self._module.params['username'] provider = self._module.params.get("provider") or {}
self._module.params['url_password'] = self._module.params['password'] self._module.params['url_username'] = provider.get('username')
self._module.params['url_password'] = provider.get('password')
host = self._module.params['host'] host = provider.get('host')
port = self._module.params['port'] port = provider.get('port')
if self._module.params['use_ssl']: if provider.get('use_ssl'):
proto = 'https' proto = 'https'
port = port or 443 port = port or 443
else: else:
@ -1174,10 +1148,10 @@ def is_text(cmd):
def is_local_nxapi(module): def is_local_nxapi(module):
transport = module.params.get('transport')
provider = module.params.get('provider') provider = module.params.get('provider')
provider_transport = provider['transport'] if provider else None if provider:
return 'nxapi' in (transport, provider_transport) return provider.get("transport") == 'nxapi'
return False
def to_command(module, commands): def to_command(module, commands):

@ -46,17 +46,6 @@ vyos_provider_spec = {
vyos_argument_spec = { vyos_argument_spec = {
'provider': dict(type='dict', options=vyos_provider_spec), 'provider': dict(type='dict', options=vyos_provider_spec),
} }
vyos_top_spec = {
'host': dict(removed_in_version=2.9),
'port': dict(removed_in_version=2.9, type='int'),
'username': dict(removed_in_version=2.9),
'password': dict(removed_in_version=2.9, no_log=True),
'ssh_keyfile': dict(removed_in_version=2.9, type='path'),
'timeout': dict(removed_in_version=2.9, type='int'),
}
vyos_argument_spec.update(vyos_top_spec)
def get_provider_argspec(): def get_provider_argspec():

@ -89,7 +89,7 @@ session_name:
""" """
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.network.eos.eos import load_config, run_commands from ansible.module_utils.network.eos.eos import load_config, run_commands
from ansible.module_utils.network.eos.eos import eos_argument_spec from ansible.module_utils.network.eos.eos import eos_argument_spec, is_local_eapi
from ansible.module_utils.six import string_types from ansible.module_utils.six import string_types
from ansible.module_utils._text import to_text from ansible.module_utils._text import to_text
@ -129,7 +129,7 @@ def map_config_to_obj(module):
output = run_commands(module, ['show banner %s' % module.params['banner']]) output = run_commands(module, ['show banner %s' % module.params['banner']])
obj = {'banner': module.params['banner'], 'state': 'absent'} obj = {'banner': module.params['banner'], 'state': 'absent'}
if output: if output:
if module.params['transport'] == 'eapi': if is_local_eapi(module):
# On EAPI we need to extract the banner text from dict key # On EAPI we need to extract the banner text from dict key
# 'loginBanner' # 'loginBanner'
if module.params['banner'] == 'login': if module.params['banner'] == 'login':

@ -101,6 +101,12 @@ options:
type: bool type: bool
default: 'no' default: 'no'
aliases: ['enable_socket'] aliases: ['enable_socket']
timeout:
description:
- The time (in seconds) to wait for the eAPI configuration to be
reflected in the running-config.
type: int
default: 30
vrf: vrf:
description: description:
- The C(vrf) argument will configure eAPI to listen for connections - The C(vrf) argument will configure eAPI to listen for connections
@ -178,10 +184,9 @@ from ansible.module_utils.network.eos.eos import eos_argument_spec
def check_transport(module): def check_transport(module):
transport = module.params['transport'] transport = (module.params['provider'] or {}).get('transport')
provider_transport = (module.params['provider'] or {}).get('transport')
if 'eapi' in (transport, provider_transport): if transport == 'eapi':
module.fail_json(msg='eos_eapi module is only supported over cli transport') module.fail_json(msg='eos_eapi module is only supported over cli transport')
@ -334,7 +339,7 @@ def verify_state(updates, module):
('local_http', 'localHttpServer'), ('local_http', 'localHttpServer'),
('socket', 'unixSocketServer')] ('socket', 'unixSocketServer')]
timeout = module.params['timeout'] or 30 timeout = module.params["timeout"]
state = module.params['state'] state = module.params['state']
while invalid_state: while invalid_state:
@ -381,6 +386,7 @@ def main():
local_http_port=dict(type='int'), local_http_port=dict(type='int'),
socket=dict(aliases=['enable_socket'], type='bool'), socket=dict(aliases=['enable_socket'], type='bool'),
timeout=dict(type="int", default=30),
vrf=dict(default='default'), vrf=dict(default='default'),

@ -361,11 +361,6 @@ def main():
supports_check_mode=True) supports_check_mode=True)
warnings = list() warnings = list()
if module.params['password'] and not module.params['configured_password']:
warnings.append(
'The "password" argument is used to authenticate the current connection. ' +
'To set a user password use "configured_password" instead.'
)
result = {'changed': False} result = {'changed': False}
if warnings: if warnings:

@ -505,15 +505,7 @@ def main():
supports_check_mode=True) supports_check_mode=True)
warnings = list() warnings = list()
if module.params['password'] and not module.params['configured_password']: result = {'changed': False, 'warnings': warnings}
warnings.append(
'The "password" argument is used to authenticate the current connection. ' +
'To set a user password use "configured_password" instead.'
)
result = {'changed': False}
if warnings:
result['warnings'] = warnings
want = map_params_to_obj(module) want = map_params_to_obj(module)
have = map_config_to_obj(module) have = map_config_to_obj(module)

@ -251,12 +251,18 @@ class PublicKeyManager(object):
def copy_key_to_node(self, base64keyfile): def copy_key_to_node(self, base64keyfile):
""" Copy key to IOS-XR node. We use SFTP because older IOS-XR versions don't handle SCP very well. """ Copy key to IOS-XR node. We use SFTP because older IOS-XR versions don't handle SCP very well.
""" """
if (self._module.params['host'] is None or self._module.params['provider']['host'] is None): provider = self._module.params.get("provider") or {}
node = provider.get('host')
if node is None:
return False return False
if (self._module.params['username'] is None or self._module.params['provider']['username'] is None): user = provider.get('username')
if user is None:
return False return False
password = provider.get('password')
ssh_keyfile = provider.get('ssh_keyfile')
if self._module.params['aggregate']: if self._module.params['aggregate']:
name = 'aggregate' name = 'aggregate'
else: else:
@ -265,11 +271,6 @@ class PublicKeyManager(object):
src = base64keyfile src = base64keyfile
dst = '/harddisk:/publickey_%s.b64' % (name) dst = '/harddisk:/publickey_%s.b64' % (name)
user = self._module.params['username'] or self._module.params['provider']['username']
node = self._module.params['host'] or self._module.params['provider']['host']
password = self._module.params['password'] or self._module.params['provider']['password']
ssh_keyfile = self._module.params['ssh_keyfile'] or self._module.params['provider']['ssh_keyfile']
ssh = paramiko.SSHClient() ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
if not ssh_keyfile: if not ssh_keyfile:
@ -284,16 +285,17 @@ class PublicKeyManager(object):
def addremovekey(self, command): def addremovekey(self, command):
""" Add or remove key based on command """ Add or remove key based on command
""" """
if (self._module.params['host'] is None or self._module.params['provider']['host'] is None): provider = self._module.params.get("provider") or {}
node = provider.get('host')
if node is None:
return False return False
if (self._module.params['username'] is None or self._module.params['provider']['username'] is None): user = provider.get('username')
if user is None:
return False return False
user = self._module.params['username'] or self._module.params['provider']['username'] password = provider.get('password')
node = self._module.params['host'] or self._module.params['provider']['host'] ssh_keyfile = provider.get('ssh_keyfile')
password = self._module.params['password'] or self._module.params['provider']['password']
ssh_keyfile = self._module.params['ssh_keyfile'] or self._module.params['provider']['ssh_keyfile']
ssh = paramiko.SSHClient() ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
@ -695,11 +697,6 @@ def main():
) )
result = {'changed': False, 'warnings': []} result = {'changed': False, 'warnings': []}
if module.params['password'] and not module.params['configured_password']:
result['warnings'].append(
'The "password" argument is used to authenticate the current connection. ' +
'To set a user password use "configured_password" instead.'
)
config_object = None config_object = None
if is_cliconf(module): if is_cliconf(module):

@ -114,44 +114,15 @@ EXAMPLES = """
reboot: no reboot: no
""" """
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.network.junos.junos import junos_argument_spec, get_param from ansible.module_utils.network.junos.junos import junos_argument_spec, get_device
from ansible.module_utils._text import to_native
try: try:
from jnpr.junos import Device
from jnpr.junos.utils.sw import SW from jnpr.junos.utils.sw import SW
from jnpr.junos.exception import ConnectError
HAS_PYEZ = True HAS_PYEZ = True
except ImportError: except ImportError:
HAS_PYEZ = False HAS_PYEZ = False
def connect(module):
host = get_param(module, 'host')
kwargs = {
'port': get_param(module, 'port') or 830,
'user': get_param(module, 'username')
}
if get_param(module, 'password'):
kwargs['passwd'] = get_param(module, 'password')
if get_param(module, 'ssh_keyfile'):
kwargs['ssh_private_key_file'] = get_param(module, 'ssh_keyfile')
kwargs['gather_facts'] = False
try:
device = Device(host, **kwargs)
device.open()
device.timeout = get_param(module, 'timeout') or 10
except ConnectError as exc:
module.fail_json(msg='unable to connect to %s: %s' % (host, to_native(exc)))
return device
def install_package(module, device): def install_package(module, device):
junos = SW(device) junos = SW(device)
package = module.params['src'] package = module.params['src']
@ -208,7 +179,7 @@ def main():
do_upgrade = module.params['force'] or False do_upgrade = module.params['force'] or False
device = connect(module) device = get_device(module)
if not module.params['force']: if not module.params['force']:
device.facts_refresh() device.facts_refresh()

@ -82,44 +82,16 @@ changed:
type: bool type: bool
""" """
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.network.junos.junos import junos_argument_spec, get_param from ansible.module_utils.network.junos.junos import junos_argument_spec, get_device
from ansible.module_utils._text import to_native from ansible.module_utils._text import to_native
try: try:
from jnpr.junos import Device
from jnpr.junos.utils.scp import SCP from jnpr.junos.utils.scp import SCP
from jnpr.junos.exception import ConnectError
HAS_PYEZ = True HAS_PYEZ = True
except ImportError: except ImportError:
HAS_PYEZ = False HAS_PYEZ = False
def connect(module):
host = get_param(module, 'host')
kwargs = {
'port': get_param(module, 'port') or 830,
'user': get_param(module, 'username')
}
if get_param(module, 'password'):
kwargs['passwd'] = get_param(module, 'password')
if get_param(module, 'ssh_keyfile'):
kwargs['ssh_private_key_file'] = get_param(module, 'ssh_keyfile')
kwargs['gather_facts'] = False
try:
device = Device(host, **kwargs)
device.open()
device.timeout = get_param(module, 'timeout') or 10
except ConnectError as exc:
module.fail_json('unable to connect to %s: %s' % (host, to_native(exc)))
return device
def transfer_files(module, device): def transfer_files(module, device):
dest = module.params['dest'] dest = module.params['dest']
recursive = module.params['recursive'] recursive = module.params['recursive']
@ -162,7 +134,7 @@ def main():
if not module.check_mode: if not module.check_mode:
# open pyez connection and transfer files via SCP # open pyez connection and transfer files via SCP
try: try:
device = connect(module) device = get_device(module)
transfer_files(module, device) transfer_files(module, device)
except Exception as ex: except Exception as ex:
module.fail_json( module.fail_json(

@ -76,7 +76,6 @@ EXAMPLES = r'''
priority: 150 priority: 150
interface: vlan10 interface: vlan10
preempt: enabled preempt: enabled
host: 68.170.147.165
- name: Ensure HSRP is configured with following params on a SVI - name: Ensure HSRP is configured with following params on a SVI
with clear text authentication with clear text authentication
@ -86,7 +85,6 @@ EXAMPLES = r'''
priority: 150 priority: 150
interface: vlan10 interface: vlan10
preempt: enabled preempt: enabled
host: 68.170.147.165
auth_type: text auth_type: text
auth_string: CISCO auth_string: CISCO
@ -98,7 +96,6 @@ EXAMPLES = r'''
priority: 150 priority: 150
interface: vlan10 interface: vlan10
preempt: enabled preempt: enabled
host: 68.170.147.165
auth_type: md5 auth_type: md5
auth_string: "0 1234" auth_string: "0 1234"
@ -110,7 +107,6 @@ EXAMPLES = r'''
priority: 150 priority: 150
interface: vlan10 interface: vlan10
preempt: enabled preempt: enabled
host: 68.170.147.165
auth_type: md5 auth_type: md5
auth_string: "7 1234" auth_string: "7 1234"
@ -119,7 +115,6 @@ EXAMPLES = r'''
group: 10 group: 10
interface: vlan10 interface: vlan10
vip: 10.1.1.1 vip: 10.1.1.1
host: 68.170.147.165
state: absent state: absent
''' '''

@ -306,15 +306,7 @@ def main():
supports_check_mode=True) supports_check_mode=True)
warnings = list() warnings = list()
if module.params['password'] and not module.params['configured_password']: result = {'changed': False, 'warnings': warnings}
warnings.append(
'The "password" argument is used to authenticate the current connection. ' +
'To set a user password use "configured_password" instead.'
)
result = {'changed': False}
if warnings:
result['warnings'] = warnings
want = map_params_to_obj(module) want = map_params_to_obj(module)
have = config_to_dict(module) have = config_to_dict(module)

@ -9,32 +9,6 @@ class ModuleDocFragment(object):
# Standard files documentation fragment # Standard files documentation fragment
DOCUMENTATION = r''' DOCUMENTATION = r'''
options: options:
authorize:
description:
- B(Deprecated)
- "Starting with Ansible 2.5 we recommend using C(connection: network_cli) and C(become: yes)."
- This option is only required if you are using eAPI.
- For more information please see the L(EOS Platform Options guide, ../network/user_guide/platform_eos.html).
- HORIZONTALLINE
- Instructs the module to enter privileged mode on the remote device
before sending any commands. If not specified, the device will
attempt to execute all commands in non-privileged mode. If the value
is not specified in the task, the value of environment variable
C(ANSIBLE_NET_AUTHORIZE) will be used instead.
type: bool
default: no
auth_pass:
description:
- B(Deprecated)
- "Starting with Ansible 2.5 we recommend using C(connection: network_cli) and C(become: yes) with C(become_pass)."
- This option is only required if you are using eAPI.
- For more information please see the L(EOS Platform Options guide, ../network/user_guide/platform_eos.html).
- HORIZONTALLINE
- Specifies the password to use if required to enter privileged mode
on the remote device. If I(authorize) is false, then this argument
does nothing. If the value is not specified in the task, the value of
environment variable C(ANSIBLE_NET_AUTH_PASS) will be used instead.
type: str
provider: provider:
description: description:
- B(Deprecated) - B(Deprecated)

@ -9,30 +9,6 @@ class ModuleDocFragment(object):
# Standard files documentation fragment # Standard files documentation fragment
DOCUMENTATION = r''' DOCUMENTATION = r'''
options: options:
authorize:
description:
- B(Deprecated)
- "Starting with Ansible 2.5 we recommend using C(connection: network_cli) and C(become: yes)."
- For more information please see the L(IOS Platform Options guide, ../network/user_guide/platform_ios.html).
- HORIZONTALLINE
- Instructs the module to enter privileged mode on the remote device
before sending any commands. If not specified, the device will
attempt to execute all commands in non-privileged mode. If the value
is not specified in the task, the value of environment variable
C(ANSIBLE_NET_AUTHORIZE) will be used instead.
type: bool
default: no
auth_pass:
description:
- B(Deprecated)
- "Starting with Ansible 2.5 we recommend using C(connection: network_cli) and C(become: yes) with C(become_pass)."
- For more information please see the L(IOS Platform Options guide, ../network/user_guide/platform_ios.html).
- HORIZONTALLINE
- Specifies the password to use if required to enter privileged mode
on the remote device. If I(authorize) is false, then this argument
does nothing. If the value is not specified in the task, the value of
environment variable C(ANSIBLE_NET_AUTH_PASS) will be used instead.
type: str
provider: provider:
description: description:
- B(Deprecated) - B(Deprecated)

@ -12,7 +12,6 @@
state: up state: up
tx_rate: ge(0) tx_rate: ge(0)
rx_rate: ge(0) rx_rate: ge(0)
authorize: yes
become: yes become: yes
register: result register: result

@ -17,7 +17,6 @@
state: up state: up
tx_rate: ge(0) tx_rate: ge(0)
rx_rate: ge(0) rx_rate: ge(0)
authorize: yes
become: yes become: yes
register: result register: result

@ -6,7 +6,6 @@
lines: lines:
- no interface port-channel 20 - no interface port-channel 20
- no interface port-channel 100 - no interface port-channel 100
authorize: yes
provider: "{{ cli }}" provider: "{{ cli }}"
become: yes become: yes
@ -14,7 +13,6 @@
eos_config: eos_config:
lines: lines:
- no channel-group 20 - no channel-group 20
authorize: yes
provider: "{{ cli }}" provider: "{{ cli }}"
parents: "{{ item }}" parents: "{{ item }}"
loop: loop:
@ -26,7 +24,6 @@
eos_linkagg: &create eos_linkagg: &create
group: 20 group: 20
state: present state: present
authorize: yes
provider: "{{ cli }}" provider: "{{ cli }}"
become: yes become: yes
register: result register: result
@ -52,7 +49,6 @@
members: members:
- Ethernet1 - Ethernet1
- Ethernet2 - Ethernet2
authorize: yes
provider: "{{ cli }}" provider: "{{ cli }}"
become: yes become: yes
register: result register: result
@ -80,7 +76,6 @@
mode: active mode: active
members: members:
- Ethernet2 - Ethernet2
authorize: yes
provider: "{{ cli }}" provider: "{{ cli }}"
become: yes become: yes
register: result register: result
@ -104,7 +99,6 @@
eos_linkagg: &remove eos_linkagg: &remove
group: 20 group: 20
state: absent state: absent
authorize: yes
provider: "{{ cli }}" provider: "{{ cli }}"
become: yes become: yes
register: result register: result
@ -128,7 +122,6 @@
aggregate: aggregate:
- { group: 20, min_links: 3 } - { group: 20, min_links: 3 }
- { group: 100, min_links: 4 } - { group: 100, min_links: 4 }
authorize: yes
provider: "{{ cli }}" provider: "{{ cli }}"
become: yes become: yes
register: result register: result
@ -155,7 +148,6 @@
aggregate: aggregate:
- { group: 20, min_links: 3 } - { group: 20, min_links: 3 }
- { group: 100, min_links: 4 } - { group: 100, min_links: 4 }
authorize: yes
provider: "{{ cli }}" provider: "{{ cli }}"
state: absent state: absent
become: yes become: yes
@ -181,7 +173,6 @@
lines: lines:
- no interface port-channel 20 - no interface port-channel 20
- no interface port-channel 100 - no interface port-channel 100
authorize: yes
provider: "{{ cli }}" provider: "{{ cli }}"
become: yes become: yes
@ -189,7 +180,6 @@
eos_config: eos_config:
lines: lines:
- no channel-group 20 - no channel-group 20
authorize: yes
provider: "{{ cli }}" provider: "{{ cli }}"
parents: "{{ item }}" parents: "{{ item }}"
become: yes become: yes

@ -14,9 +14,11 @@
with_items: "{{ test_items }}" with_items: "{{ test_items }}"
loop_control: loop_control:
loop_var: test_case_to_run loop_var: test_case_to_run
tags: network_cli
- name: run test cases (connection=local) - name: run test cases (connection=local)
include: "{{ test_case_to_run }} ansible_connection=local ansible_become=no" include: "{{ test_case_to_run }} ansible_connection=local ansible_become=no"
with_items: "{{ test_items }}" with_items: "{{ test_items }}"
loop_control: loop_control:
loop_var: test_case_to_run loop_var: test_case_to_run
tags: local

@ -3,8 +3,8 @@
find: find:
paths: "{{ role_path }}/tests/eapi" paths: "{{ role_path }}/tests/eapi"
patterns: "{{ testcase }}.yaml" patterns: "{{ testcase }}.yaml"
delegate_to: localhost
register: test_cases register: test_cases
delegate_to: localhost
- name: set test_items - name: set test_items
set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}"
@ -14,9 +14,11 @@
with_items: "{{ test_items }}" with_items: "{{ test_items }}"
loop_control: loop_control:
loop_var: test_case_to_run loop_var: test_case_to_run
tags: httpapi
- name: run test case (connection=local) - name: run test cases (connection=local)
include: "{{ test_case_to_run }} ansible_connection=local" include: "{{ test_case_to_run }} ansible_connection=local"
with_items: "{{ test_items }}" with_items: "{{ test_items }}"
loop_control: loop_control:
loop_var: test_case_to_run loop_var: test_case_to_run
tags: local

@ -10,7 +10,6 @@
eos_config: eos_config:
lines: lines:
- no ip route 192.168.3.0/24 192.168.0.1 - no ip route 192.168.3.0/24 192.168.0.1
authorize: yes
provider: "{{ cli }}" provider: "{{ cli }}"
become: yes become: yes
@ -19,7 +18,6 @@
address: 192.168.3.0/24 address: 192.168.3.0/24
next_hop: 192.168.0.1 next_hop: 192.168.0.1
admin_distance: 2 admin_distance: 2
authorize: yes
provider: "{{ cli }}" provider: "{{ cli }}"
become: yes become: yes
register: result register: result
@ -34,7 +32,6 @@
address: 192.168.3.0/250 address: 192.168.3.0/250
next_hop: 192.168.0.1 next_hop: 192.168.0.1
admin_distance: 2 admin_distance: 2
authorize: yes
provider: "{{ cli }}" provider: "{{ cli }}"
become: yes become: yes
register: result register: result
@ -48,7 +45,6 @@
eos_config: eos_config:
lines: lines:
- no ip route 192.168.3.0/24 192.168.0.1 - no ip route 192.168.3.0/24 192.168.0.1
authorize: yes
provider: "{{ cli }}" provider: "{{ cli }}"
become: yes become: yes
@ -65,7 +61,6 @@
state: up state: up
tx_rate: ge(0) tx_rate: ge(0)
rx_rate: ge(0) rx_rate: ge(0)
authorize: yes
provider: "{{ cli }}" provider: "{{ cli }}"
become: yes become: yes
register: result register: result

@ -10,7 +10,6 @@
eos_config: eos_config:
lines: lines:
- no ip route 192.168.3.0/24 192.168.0.1 - no ip route 192.168.3.0/24 192.168.0.1
authorize: yes
provider: "{{ eapi }}" provider: "{{ eapi }}"
become: yes become: yes
@ -19,7 +18,6 @@
address: 192.168.3.0/24 address: 192.168.3.0/24
next_hop: 192.168.0.1 next_hop: 192.168.0.1
admin_distance: 2 admin_distance: 2
authorize: yes
provider: "{{ eapi }}" provider: "{{ eapi }}"
become: yes become: yes
register: result register: result
@ -34,7 +32,6 @@
address: 192.168.3.0/250 address: 192.168.3.0/250
next_hop: 192.168.0.1 next_hop: 192.168.0.1
admin_distance: 2 admin_distance: 2
authorize: yes
provider: "{{ eapi }}" provider: "{{ eapi }}"
become: yes become: yes
register: result register: result
@ -48,7 +45,6 @@
eos_config: eos_config:
lines: lines:
- no ip route 192.168.3.0/24 192.168.0.1 - no ip route 192.168.3.0/24 192.168.0.1
authorize: yes
provider: "{{ eapi }}" provider: "{{ eapi }}"
become: yes become: yes
@ -65,7 +61,6 @@
state: up state: up
tx_rate: ge(0) tx_rate: ge(0)
rx_rate: ge(0) rx_rate: ge(0)
authorize: yes
provider: "{{ eapi }}" provider: "{{ eapi }}"
become: yes become: yes
register: result register: result

@ -7,7 +7,6 @@
- no ip route 192.168.3.0/24 192.168.0.1 - no ip route 192.168.3.0/24 192.168.0.1
- no ip route 192.168.4.0/24 192.168.0.1 - no ip route 192.168.4.0/24 192.168.0.1
- no ip route 192.168.5.0/24 192.168.0.1 - no ip route 192.168.5.0/24 192.168.0.1
authorize: yes
provider: "{{ cli }}" provider: "{{ cli }}"
become: yes become: yes
@ -16,7 +15,6 @@
address: 192.168.3.0/24 address: 192.168.3.0/24
next_hop: 192.168.0.1 next_hop: 192.168.0.1
admin_distance: 2 admin_distance: 2
authorize: yes
provider: "{{ cli }}" provider: "{{ cli }}"
become: yes become: yes
register: result register: result
@ -40,7 +38,6 @@
address: 192.168.3.0/24 address: 192.168.3.0/24
next_hop: 192.168.0.1 next_hop: 192.168.0.1
admin_distance: 2 admin_distance: 2
authorize: yes
provider: "{{ cli }}" provider: "{{ cli }}"
state: absent state: absent
become: yes become: yes
@ -65,7 +62,6 @@
aggregate: aggregate:
- { address: 192.168.4.0/24, next_hop: 192.168.0.1 } - { address: 192.168.4.0/24, next_hop: 192.168.0.1 }
- { address: 192.168.5.0/24, next_hop: 192.168.0.1 } - { address: 192.168.5.0/24, next_hop: 192.168.0.1 }
authorize: yes
provider: "{{ cli }}" provider: "{{ cli }}"
become: yes become: yes
register: result register: result
@ -90,7 +86,6 @@
aggregate: aggregate:
- { address: 192.168.4.0/24, next_hop: 192.168.0.1 } - { address: 192.168.4.0/24, next_hop: 192.168.0.1 }
- { address: 192.168.5.0/24, next_hop: 192.168.0.1 } - { address: 192.168.5.0/24, next_hop: 192.168.0.1 }
authorize: yes
state: absent state: absent
provider: "{{ cli }}" provider: "{{ cli }}"
become: yes become: yes
@ -117,7 +112,6 @@
- no ip route 192.168.3.0/24 192.168.0.1 - no ip route 192.168.3.0/24 192.168.0.1
- no ip route 192.168.4.0/24 192.168.0.1 - no ip route 192.168.4.0/24 192.168.0.1
- no ip route 192.168.5.0/24 192.168.0.1 - no ip route 192.168.5.0/24 192.168.0.1
authorize: yes
provider: "{{ cli }}" provider: "{{ cli }}"
become: yes become: yes

@ -8,7 +8,6 @@
eos_config: eos_config:
lines: lines:
- no ip route 192.168.3.0/24 192.168.0.1 - no ip route 192.168.3.0/24 192.168.0.1
authorize: yes
provider: "{{ cli }}" provider: "{{ cli }}"
become: yes become: yes
@ -17,7 +16,6 @@
address: 192.168.3.0/24 address: 192.168.3.0/24
next_hop: 192.168.0.1 next_hop: 192.168.0.1
admin_distance: 2 admin_distance: 2
authorize: yes
provider: "{{ cli }}" provider: "{{ cli }}"
become: yes become: yes
register: result register: result
@ -31,7 +29,6 @@
eos_config: eos_config:
lines: lines:
- no ip route 192.168.3.0/24 192.168.0.1 - no ip route 192.168.3.0/24 192.168.0.1
authorize: yes
provider: "{{ cli }}" provider: "{{ cli }}"
become: yes become: yes

@ -6,7 +6,6 @@
privilege: 15 privilege: 15
role: network-operator role: network-operator
state: present state: present
authorize: yes
provider: "{{ cli }}" provider: "{{ cli }}"
configured_password: pass123 configured_password: pass123
become: yes become: yes
@ -36,6 +35,5 @@
name: auth_user name: auth_user
state: absent state: absent
provider: "{{ cli }}" provider: "{{ cli }}"
authorize: yes
become: yes become: yes
register: result register: result

@ -18,7 +18,6 @@
role: network-operator role: network-operator
state: present state: present
configured_password: test1 configured_password: test1
authorize: yes
provider: "{{ cli }}" provider: "{{ cli }}"
become: yes become: yes
register: result register: result
@ -37,7 +36,6 @@
privilege: 15 privilege: 15
state: present state: present
configured_password: test1 configured_password: test1
authorize: yes
update_password: on_create update_password: on_create
provider: "{{ cli }}" provider: "{{ cli }}"
become: yes become: yes
@ -55,7 +53,6 @@
aggregate: aggregate:
- { name: ansibletest2, configured_password: test2 } - { name: ansibletest2, configured_password: test2 }
- { name: ansibletest3, configured_password: test3 } - { name: ansibletest3, configured_password: test3 }
authorize: yes
state: present state: present
role: network-operator role: network-operator
provider: "{{ cli }}" provider: "{{ cli }}"
@ -77,7 +74,6 @@
name: faileduser1 name: faileduser1
privilege: 15 privilege: 15
state: present state: present
authorize: yes
provider: "{{ cli }}" provider: "{{ cli }}"
become: yes become: yes
ignore_errors: yes ignore_errors: yes
@ -97,5 +93,4 @@
- no username ansibletest3 - no username ansibletest3
- no username ansibletest4 - no username ansibletest4
provider: "{{ cli }}" provider: "{{ cli }}"
authorize: yes
become: yes become: yes

@ -18,7 +18,6 @@
role: network-operator role: network-operator
state: present state: present
configured_password: test1 configured_password: test1
authorize: yes
provider: "{{ cli }}" provider: "{{ cli }}"
become: yes become: yes
register: result register: result

@ -6,7 +6,6 @@
- no vlan 4000 - no vlan 4000
- no vlan 4001 - no vlan 4001
- no vlan 4002 - no vlan 4002
authorize: yes
provider: "{{ cli }}" provider: "{{ cli }}"
become: yes become: yes
@ -16,7 +15,6 @@
- switchport - switchport
- no switchport access vlan 4000 - no switchport access vlan 4000
parents: interface Ethernet1 parents: interface Ethernet1
authorize: yes
provider: "{{ cli }}" provider: "{{ cli }}"
become: yes become: yes
@ -26,7 +24,6 @@
- switchport - switchport
- no switchport access vlan 4000 - no switchport access vlan 4000
parents: interface Ethernet2 parents: interface Ethernet2
authorize: yes
provider: "{{ cli }}" provider: "{{ cli }}"
become: yes become: yes
@ -35,7 +32,6 @@
vlan_id: 4000 vlan_id: 4000
name: vlan-4000 name: vlan-4000
state: present state: present
authorize: yes
provider: "{{ cli }}" provider: "{{ cli }}"
become: yes become: yes
register: result register: result
@ -53,7 +49,6 @@
vlan_id: 4000 vlan_id: 4000
name: vlan-4000 name: vlan-4000
state: present state: present
authorize: yes
provider: "{{ cli }}" provider: "{{ cli }}"
become: yes become: yes
register: result register: result
@ -70,7 +65,6 @@
vlan_id: 4000 vlan_id: 4000
name: vlan-4000-new name: vlan-4000-new
state: suspend state: suspend
authorize: yes
provider: "{{ cli }}" provider: "{{ cli }}"
become: yes become: yes
register: result register: result
@ -89,7 +83,6 @@
vlan_id: 4000 vlan_id: 4000
name: vlan-4000-new name: vlan-4000-new
state: suspend state: suspend
authorize: yes
provider: "{{ cli }}" provider: "{{ cli }}"
become: yes become: yes
register: result register: result
@ -105,7 +98,6 @@
eos_vlan: eos_vlan:
vlan_id: 4000 vlan_id: 4000
state: active state: active
authorize: yes
provider: "{{ cli }}" provider: "{{ cli }}"
become: yes become: yes
register: result register: result
@ -128,7 +120,6 @@
associated_interfaces: associated_interfaces:
- Ethernet1 - Ethernet1
- Ethernet2 - Ethernet2
authorize: yes
provider: "{{ cli }}" provider: "{{ cli }}"
become: yes become: yes
register: result register: result
@ -151,7 +142,6 @@
interfaces: interfaces:
- Ethernet 1 # interface name space scenario - Ethernet 1 # interface name space scenario
- Ethernet 2 # interface name space scenario - Ethernet 2 # interface name space scenario
authorize: yes
provider: "{{ cli }}" provider: "{{ cli }}"
become: yes become: yes
register: result register: result
@ -169,7 +159,6 @@
state: present state: present
associated_interfaces: associated_interfaces:
- test - test
authorize: yes
provider: "{{ cli }}" provider: "{{ cli }}"
become: yes become: yes
register: result register: result
@ -185,7 +174,6 @@
state: present state: present
interfaces: interfaces:
- Ethernet1 - Ethernet1
authorize: yes
provider: "{{ cli }}" provider: "{{ cli }}"
become: yes become: yes
register: result register: result
@ -205,7 +193,6 @@
state: present state: present
interfaces: interfaces:
- Ethernet 1 # space scenario - Ethernet 1 # space scenario
authorize: yes
provider: "{{ cli }}" provider: "{{ cli }}"
become: yes become: yes
register: result register: result
@ -223,7 +210,6 @@
- {vlan_id: 4000, state: absent} - {vlan_id: 4000, state: absent}
- {vlan_id: 4001, name: vlan-4001} - {vlan_id: 4001, name: vlan-4001}
state: present state: present
authorize: yes
provider: "{{ cli }}" provider: "{{ cli }}"
become: yes become: yes
register: result register: result
@ -243,7 +229,6 @@
- {vlan_id: 4000, state: absent} - {vlan_id: 4000, state: absent}
- {vlan_id: 4001, name: vlan-4001} - {vlan_id: 4001, name: vlan-4001}
state: present state: present
authorize: yes
provider: "{{ cli }}" provider: "{{ cli }}"
become: yes become: yes
register: result register: result
@ -262,7 +247,6 @@
name: vlan-4002 name: vlan-4002
state: present state: present
purge: yes purge: yes
authorize: yes
provider: "{{ cli }}" provider: "{{ cli }}"
become: yes become: yes
register: result register: result
@ -283,7 +267,6 @@
name: vlan-4002 name: vlan-4002
state: present state: present
purge: yes purge: yes
authorize: yes
provider: "{{ cli }}" provider: "{{ cli }}"
become: yes become: yes
register: result register: result

@ -8,7 +8,6 @@
eos_config: eos_config:
lines: lines:
- no vlan 4000 - no vlan 4000
authorize: yes
provider: "{{ cli }}" provider: "{{ cli }}"
become: yes become: yes
@ -17,7 +16,6 @@
vlan_id: 4000 vlan_id: 4000
name: vlan-4000 name: vlan-4000
state: present state: present
authorize: yes
provider: "{{ cli }}" provider: "{{ cli }}"
become: yes become: yes
register: result register: result
@ -34,7 +32,6 @@
eos_config: eos_config:
lines: lines:
- no vlan 4000 - no vlan 4000
authorize: yes
provider: "{{ cli }}" provider: "{{ cli }}"
become: yes become: yes

@ -4,7 +4,6 @@
eos_vrf: eos_vrf:
name: "{{ item }}" name: "{{ item }}"
state: absent state: absent
authorize: yes
provider: "{{ cli }}" provider: "{{ cli }}"
become: yes become: yes
with_items: with_items:
@ -20,7 +19,6 @@
name: test name: test
rd: 1:200 rd: 1:200
state: present state: present
authorize: yes
provider: "{{ cli }}" provider: "{{ cli }}"
become: yes become: yes
register: result register: result
@ -38,7 +36,6 @@
name: test name: test
rd: 1:200 rd: 1:200
state: present state: present
authorize: yes
provider: "{{ cli }}" provider: "{{ cli }}"
become: yes become: yes
register: result register: result
@ -55,7 +52,6 @@
name: test name: test
rd: 1:201 rd: 1:201
state: present state: present
authorize: yes
provider: "{{ cli }}" provider: "{{ cli }}"
become: yes become: yes
register: result register: result
@ -73,7 +69,6 @@
name: test name: test
rd: 1:201 rd: 1:201
state: present state: present
authorize: yes
provider: "{{ cli }}" provider: "{{ cli }}"
become: yes become: yes
register: result register: result
@ -90,7 +85,6 @@
name: test name: test
rd: 1:201 rd: 1:201
state: present state: present
authorize: yes
interfaces: interfaces:
- Ethernet2 - Ethernet2
associated_interfaces: associated_interfaces:
@ -112,7 +106,6 @@
name: test name: test
rd: 1:201 rd: 1:201
state: present state: present
authorize: yes
interfaces: interfaces:
- ethernet 2 # interface name modified to test case insensitive and space scenario - ethernet 2 # interface name modified to test case insensitive and space scenario
provider: "{{ cli }}" provider: "{{ cli }}"
@ -130,7 +123,6 @@
eos_vrf: eos_vrf:
name: test name: test
state: present state: present
authorize: yes
associated_interfaces: associated_interfaces:
- test - test
provider: "{{ cli }}" provider: "{{ cli }}"
@ -147,7 +139,6 @@
name: test1 name: test1
rd: 1:202 rd: 1:202
state: present state: present
authorize: yes
interfaces: interfaces:
- loopback10 - loopback10
- loopback11 - loopback11
@ -184,7 +175,6 @@
name: test1 name: test1
rd: 1:202 rd: 1:202
state: present state: present
authorize: yes
interfaces: interfaces:
- loopback10 - loopback10
- loopback11 - loopback11
@ -206,7 +196,6 @@
eos_vrf: eos_vrf:
name: "{{ item }}" name: "{{ item }}"
state: absent state: absent
authorize: yes
provider: "{{ cli }}" provider: "{{ cli }}"
become: yes become: yes
with_items: with_items:
@ -220,7 +209,6 @@
- { name: test2, rd: "1:202" } - { name: test2, rd: "1:202" }
- { name: test3, rd: "1:203" } - { name: test3, rd: "1:203" }
state: present state: present
authorize: yes
provider: "{{ cli }}" provider: "{{ cli }}"
become: yes become: yes
register: result register: result
@ -241,7 +229,6 @@
- { name: test2, rd: "1:202" } - { name: test2, rd: "1:202" }
- { name: test3, rd: "1:203" } - { name: test3, rd: "1:203" }
state: present state: present
authorize: yes
provider: "{{ cli }}" provider: "{{ cli }}"
become: yes become: yes
register: result register: result
@ -260,7 +247,6 @@
- { name: test5, rd: "1:205" } - { name: test5, rd: "1:205" }
state: present state: present
purge: yes purge: yes
authorize: yes
provider: "{{ cli }}" provider: "{{ cli }}"
become: yes become: yes
register: result register: result
@ -282,7 +268,6 @@
eos_vrf: eos_vrf:
name: test name: test
state: absent state: absent
authorize: yes
provider: "{{ cli }}" provider: "{{ cli }}"
become: yes become: yes
@ -290,7 +275,6 @@
eos_vrf: eos_vrf:
name: test name: test
state: absent state: absent
authorize: yes
provider: "{{ cli }}" provider: "{{ cli }}"
become: yes become: yes
@ -303,7 +287,6 @@
- { name: test4 } - { name: test4 }
- { name: test5 } - { name: test5 }
state: absent state: absent
authorize: yes
provider: "{{ cli }}" provider: "{{ cli }}"
become: yes become: yes
@ -316,7 +299,6 @@
- { name: test4 } - { name: test4 }
- { name: test5 } - { name: test5 }
state: absent state: absent
authorize: yes
provider: "{{ cli }}" provider: "{{ cli }}"
become: yes become: yes

@ -8,7 +8,6 @@
net_vrf: net_vrf:
name: test name: test
state: absent state: absent
authorize: yes
provider: "{{ cli }}" provider: "{{ cli }}"
become: yes become: yes
@ -17,7 +16,6 @@
name: test name: test
rd: 1:200 rd: 1:200
state: present state: present
authorize: yes
provider: "{{ cli }}" provider: "{{ cli }}"
become: yes become: yes
register: result register: result
@ -34,7 +32,6 @@
net_vrf: net_vrf:
name: test name: test
state: absent state: absent
authorize: yes
provider: "{{ cli }}" provider: "{{ cli }}"
become: yes become: yes

@ -31,7 +31,6 @@
- name: unexpected unsuccessful ping - name: unexpected unsuccessful ping
ios_ping: &invalid_ip ios_ping: &invalid_ip
dest: '10.255.255.250' dest: '10.255.255.250'
timeout: 45
provider: "{{ cli }}" provider: "{{ cli }}"
register: uup register: uup
ignore_errors: yes ignore_errors: yes

@ -22,6 +22,9 @@ from ansible.modules.network.eos import eos_banner
from units.modules.utils import set_module_args from units.modules.utils import set_module_args
from .eos_module import TestEosModule, load_fixture from .eos_module import TestEosModule, load_fixture
CLI = dict(transport="cli")
EAPI = dict(transport="eapi")
class TestEosBannerModule(TestEosModule): class TestEosBannerModule(TestEosModule):
@ -51,34 +54,32 @@ class TestEosBannerModule(TestEosModule):
self.load_config.return_value = dict(diff=None, session='session') self.load_config.return_value = dict(diff=None, session='session')
def test_eos_banner_create_with_cli_transport(self): def test_eos_banner_create_with_cli_transport(self):
set_module_args(dict(banner='login', text='test\nbanner\nstring', set_module_args(dict(banner='login', text='test\nbanner\nstring', provider=CLI))
transport='cli'))
commands = ['banner login', 'test', 'banner', 'string', 'EOF'] commands = ['banner login', 'test', 'banner', 'string', 'EOF']
self.execute_module(changed=True, commands=commands) self.execute_module(changed=True, commands=commands)
def test_eos_banner_remove_with_cli_transport(self): def test_eos_banner_remove_with_cli_transport(self):
set_module_args(dict(banner='login', state='absent', transport='cli')) set_module_args(dict(banner='login', state='absent', provider=CLI))
commands = ['no banner login'] commands = ['no banner login']
self.execute_module(changed=True, commands=commands) self.execute_module(changed=True, commands=commands)
def test_eos_banner_create_with_eapi_transport(self): def test_eos_banner_create_with_eapi_transport(self):
set_module_args(dict(banner='login', text='test\nbanner\nstring', set_module_args(dict(banner='login', text='test\nbanner\nstring', provider=EAPI))
transport='eapi'))
commands = ['banner login'] commands = ['banner login']
inputs = ['test\nbanner\nstring'] inputs = ['test\nbanner\nstring']
self.execute_module(changed=True, commands=commands, inputs=inputs, transport='eapi') self.execute_module(changed=True, commands=commands, inputs=inputs, transport='eapi')
def test_eos_banner_remove_with_eapi_transport(self): def test_eos_banner_remove_with_eapi_transport(self):
set_module_args(dict(banner='login', state='absent', transport='eapi')) set_module_args(dict(banner='login', state='absent', provider=EAPI))
commands = ['no banner login'] commands = ['no banner login']
self.execute_module(changed=True, commands=commands, transport='eapi') self.execute_module(changed=True, commands=commands, transport='eapi')
def test_eos_banner_nochange_with_cli_transport(self): def test_eos_banner_nochange_with_cli_transport(self):
banner_text = load_fixture('eos_banner_show_banner.txt').strip() banner_text = load_fixture('eos_banner_show_banner.txt').strip()
set_module_args(dict(banner='login', text=banner_text, transport='cli')) set_module_args(dict(banner='login', text=banner_text, provider=CLI))
self.execute_module() self.execute_module()
def test_eos_banner_nochange_with_eapi_transport(self): def test_eos_banner_nochange_with_eapi_transport(self):
banner_text = load_fixture('eos_banner_show_banner.txt').strip() banner_text = load_fixture('eos_banner_show_banner.txt').strip()
set_module_args(dict(banner='login', text=banner_text, transport='eapi')) set_module_args(dict(banner='login', text=banner_text, provider=EAPI))
self.execute_module(transport='eapi') self.execute_module(transport='eapi')

@ -59,7 +59,7 @@ class TestIosPingModule(TestIosModule):
def test_ios_ping_expected_failure(self): def test_ios_ping_expected_failure(self):
''' Test for unsuccessful pings when destination should not be reachable ''' ''' Test for unsuccessful pings when destination should not be reachable '''
set_module_args(dict(count=2, dest="10.255.255.250", state="absent", timeout=45)) set_module_args(dict(count=2, dest="10.255.255.250", state="absent"))
self.execute_module() self.execute_module()
def test_ios_ping_unexpected_success(self): def test_ios_ping_unexpected_success(self):
@ -69,5 +69,5 @@ class TestIosPingModule(TestIosModule):
def test_ios_ping_unexpected_failure(self): def test_ios_ping_unexpected_failure(self):
''' Test for unsuccessful pings when destination should be reachable - FAIL. ''' ''' Test for unsuccessful pings when destination should be reachable - FAIL. '''
set_module_args(dict(count=2, dest="10.255.255.250", timeout=45)) set_module_args(dict(count=2, dest="10.255.255.250"))
self.execute_module(failed=True) self.execute_module(failed=True)

@ -22,14 +22,13 @@ __metaclass__ = type
from units.compat.mock import patch, MagicMock from units.compat.mock import patch, MagicMock
from units.modules.utils import set_module_args from units.modules.utils import set_module_args
from .junos_module import TestJunosModule from .junos_module import TestJunosModule
jnpr_mock = MagicMock()
jnpr_mock = MagicMock()
modules = { modules = {
'jnpr': jnpr_mock, 'jnpr': jnpr_mock,
'jnpr.junos': jnpr_mock.junos, 'jnpr.junos': jnpr_mock.junos,
'jnpr.junos.utils': jnpr_mock.junos.utils, 'jnpr.junos.utils': jnpr_mock.junos.utils,
'jnpr.junos.utils.sw': jnpr_mock.junos.utils.sw, 'jnpr.junos.utils.sw': jnpr_mock.junos.utils.sw,
'jnpr.junos.exception': jnpr_mock.junos.execption
} }
module_patcher = patch.dict('sys.modules', modules) module_patcher = patch.dict('sys.modules', modules)
module_patcher.start() module_patcher.start()
@ -37,45 +36,38 @@ module_patcher.start()
from ansible.modules.network.junos import junos_package from ansible.modules.network.junos import junos_package
class TestJunosCommandModule(TestJunosModule): class TestJunosPackageModule(TestJunosModule):
module = junos_package module = junos_package
def setUp(self): def setUp(self):
super(TestJunosCommandModule, self).setUp() super(TestJunosPackageModule, self).setUp()
self.mock_get_device = patch('ansible.modules.network.junos.junos_package.get_device')
self.get_device = self.mock_get_device.start()
def tearDown(self): def tearDown(self):
super(TestJunosCommandModule, self).tearDown() super(TestJunosPackageModule, self).tearDown()
self.mock_get_device.stop()
def test_junos_package_src(self): def test_junos_package_src(self):
set_module_args(dict(src='junos-vsrx-12.1X46-D10.2-domestic.tgz')) set_module_args(dict(src='junos-vsrx-12.1X46-D10.2-domestic.tgz'))
result = self.execute_module(changed=True) self.execute_module(changed=True)
args, kwargs = jnpr_mock.junos.utils.sw.SW().install.call_args
self.assertEqual(args[0], 'junos-vsrx-12.1X46-D10.2-domestic.tgz') args, _kwargs = jnpr_mock.junos.utils.sw.SW().install.call_args
self.assertEqual(result['changed'], True) self.assertEqual(args, ('junos-vsrx-12.1X46-D10.2-domestic.tgz',))
def test_junos_package_src_fail(self): def test_junos_package_src_fail(self):
jnpr_mock.junos.utils.sw.SW().install.return_value = 0 jnpr_mock.junos.utils.sw.SW().install.return_value = 0
set_module_args(dict(src='junos-vsrx-12.1X46-D10.2-domestic.tgz')) set_module_args(dict(src='junos-vsrx-12.1X46-D10.2-domestic.tgz'))
result = self.execute_module(changed=True, failed=True) result = self.execute_module(changed=True, failed=True)
self.assertEqual(result['msg'], 'Unable to install package on device') self.assertEqual(result['msg'], 'Unable to install package on device')
def test_junos_package_src_no_copy(self): def test_junos_package_src_no_copy(self):
jnpr_mock.junos.utils.sw.SW().install.return_value = 1 jnpr_mock.junos.utils.sw.SW().install.return_value = 1
set_module_args(dict(src='junos-vsrx-12.1X46-D10.2-domestic.tgz', no_copy=True)) set_module_args(dict(src='junos-vsrx-12.1X46-D10.2-domestic.tgz', no_copy=True))
result = self.execute_module(changed=True)
args, kwargs = jnpr_mock.junos.utils.sw.SW().install.call_args
self.assertEqual(kwargs['no_copy'], True)
def test_junos_package_device_param(self):
set_module_args(dict(src='junos-vsrx-12.1X46-D10.2-domestic.tgz',
provider={'username': 'unit', 'host': 'test', 'ssh_keyfile': 'path',
'password': 'test', 'port': 234}))
self.execute_module(changed=True) self.execute_module(changed=True)
args, kwargs = jnpr_mock.junos.Device.call_args
self.assertEqual(args[0], 'test') args, kwargs = jnpr_mock.junos.utils.sw.SW().install.call_args
self.assertEqual(kwargs['passwd'], 'test') self.assertEqual(args, ('junos-vsrx-12.1X46-D10.2-domestic.tgz',))
self.assertEqual(kwargs['ssh_private_key_file'], 'path') self.assertEqual(kwargs['no_copy'], True)
self.assertEqual(kwargs['port'], 234)
self.assertEqual(kwargs['user'], 'unit')

@ -22,72 +22,61 @@ __metaclass__ = type
from units.compat.mock import patch, MagicMock from units.compat.mock import patch, MagicMock
from units.modules.utils import set_module_args from units.modules.utils import set_module_args
from .junos_module import TestJunosModule from .junos_module import TestJunosModule
jnpr_mock = MagicMock()
scp_mock = MagicMock()
jnpr_mock = MagicMock()
modules = { modules = {
'jnpr': jnpr_mock, 'jnpr': jnpr_mock,
'jnpr.junos': jnpr_mock.junos, 'jnpr.junos': jnpr_mock.junos,
'jnpr.junos.utils': jnpr_mock.junos.utils, 'jnpr.junos.utils': jnpr_mock.junos.utils,
'jnpr.junos.utils.scp': jnpr_mock.junos.utils.scp, 'jnpr.junos.utils.scp': jnpr_mock.junos.utils.scp,
'jnpr.junos.exception': jnpr_mock.junos.execption
} }
module_patcher = patch.dict('sys.modules', modules) module_patcher = patch.dict('sys.modules', modules)
module_patcher.start() module_patcher.start()
jnpr_mock.junos.utils.scp.SCP().__enter__.return_value = scp_mock
from ansible.modules.network.junos import junos_scp from ansible.modules.network.junos import junos_scp
class TestJunosCommandModule(TestJunosModule): class TestJunosScpModule(TestJunosModule):
module = junos_scp module = junos_scp
def setUp(self): def setUp(self):
super(TestJunosCommandModule, self).setUp() super(TestJunosScpModule, self).setUp()
self.mock_get_device = patch('ansible.modules.network.junos.junos_scp.get_device')
self.get_device = self.mock_get_device.start()
self.mock_scp = patch('ansible.modules.network.junos.junos_scp.SCP')
self.scp = self.mock_scp.start()
self.scp_mock = MagicMock()
self.scp().__enter__.return_value = self.scp_mock
def tearDown(self): def tearDown(self):
super(TestJunosCommandModule, self).tearDown() super(TestJunosScpModule, self).tearDown()
self.mock_get_device.stop()
self.mock_scp.stop()
def test_junos_scp_src(self): def test_junos_scp_src(self):
set_module_args(dict(src='test.txt')) set_module_args(dict(src='test.txt'))
result = self.execute_module(changed=True) self.execute_module(changed=True)
args, kwargs = scp_mock.put.call_args
self.assertEqual(args[0], 'test.txt') self.scp_mock.put.assert_called_once_with('test.txt', remote_path='.', recursive=False)
self.assertEqual(result['changed'], True)
def test_junos_scp_src_fail(self): def test_junos_scp_src_fail(self):
scp_mock.put.side_effect = OSError("[Errno 2] No such file or directory: 'text.txt'") self.scp_mock.put.side_effect = OSError("[Errno 2] No such file or directory: 'text.txt'")
set_module_args(dict(src='test.txt')) set_module_args(dict(src='test.txt'))
result = self.execute_module(changed=True, failed=True) result = self.execute_module(changed=True, failed=True)
self.assertEqual(result['msg'], "[Errno 2] No such file or directory: 'text.txt'") self.assertEqual(result['msg'], "[Errno 2] No such file or directory: 'text.txt'")
def test_junos_scp_remote_src(self): def test_junos_scp_remote_src(self):
set_module_args(dict(src='test.txt', remote_src=True)) set_module_args(dict(src='test.txt', remote_src=True))
result = self.execute_module(changed=True) self.execute_module(changed=True)
args, kwargs = scp_mock.get.call_args
self.assertEqual(args[0], 'test.txt') self.scp_mock.get.assert_called_once_with('test.txt', local_path='.', recursive=False)
self.assertEqual(result['changed'], True)
def test_junos_scp_all(self): def test_junos_scp_all(self):
set_module_args(dict(src='test', remote_src=True, dest="tmp", recursive=True)) set_module_args(dict(src='test', remote_src=True, dest="tmp", recursive=True))
result = self.execute_module(changed=True)
args, kwargs = scp_mock.get.call_args
self.assertEqual(args[0], 'test')
self.assertEqual(kwargs['local_path'], 'tmp')
self.assertEqual(kwargs['recursive'], True)
self.assertEqual(result['changed'], True)
def test_junos_scp_device_param(self):
set_module_args(dict(src='test.txt',
provider={'username': 'unit', 'host': 'test', 'ssh_keyfile': 'path',
'password': 'test', 'port': 234}))
self.execute_module(changed=True) self.execute_module(changed=True)
args, kwargs = jnpr_mock.junos.Device.call_args
self.assertEqual(args[0], 'test') self.scp_mock.get.assert_called_once_with('test', local_path='tmp', recursive=True)
self.assertEqual(kwargs['passwd'], 'test')
self.assertEqual(kwargs['ssh_private_key_file'], 'path')
self.assertEqual(kwargs['port'], 234)
self.assertEqual(kwargs['user'], 'unit')

@ -55,7 +55,7 @@ class TestNxosHsrpModule(TestNxosModule):
priority='150', priority='150',
interface='Ethernet1/2', interface='Ethernet1/2',
preempt='enabled', preempt='enabled',
host='192.0.2.1')) ))
result = self.execute_module(changed=True) result = self.execute_module(changed=True)
self.assertEqual(sorted(result['commands']), sorted(['config t', self.assertEqual(sorted(result['commands']), sorted(['config t',
'interface ethernet1/2', 'interface ethernet1/2',

Loading…
Cancel
Save