mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 12:50:22 -07:00
updates ios modules to support persistent socket (#21258)
* updates all ios modules to support persistent socket * adds ios action plugin to connect to device * adds exec_command() to ios shared module * fixes ios_config and ios_template local action * update all unit test cases * adds base test module for ios module testing
This commit is contained in:
parent
8bf69411d9
commit
7f1c43e597
19 changed files with 493 additions and 737 deletions
|
@ -35,7 +35,6 @@ description:
|
|||
commands that are not already configured. The config source can
|
||||
be a set of commands or a template.
|
||||
deprecated: Deprecated in 2.2. Use M(ios_config) instead.
|
||||
extends_documentation_fragment: ios
|
||||
options:
|
||||
src:
|
||||
description:
|
||||
|
@ -108,52 +107,15 @@ updates:
|
|||
returned: always
|
||||
type: list
|
||||
sample: ['...', '...']
|
||||
start:
|
||||
description: The time the job started
|
||||
returned: always
|
||||
type: str
|
||||
sample: "2016-11-16 10:38:15.126146"
|
||||
end:
|
||||
description: The time the job ended
|
||||
returned: always
|
||||
type: str
|
||||
sample: "2016-11-16 10:38:25.595612"
|
||||
delta:
|
||||
description: The time elapsed to perform all operations
|
||||
returned: always
|
||||
type: str
|
||||
sample: "0:00:10.469466"
|
||||
"""
|
||||
from functools import partial
|
||||
|
||||
from ansible.module_utils import ios
|
||||
from ansible.module_utils import ios_cli
|
||||
from ansible.module_utils.ios import load_config, get_config
|
||||
from ansible.module_utils.ios import ios_argument_spec, check_args
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.local import LocalAnsibleModule
|
||||
from ansible.module_utils.network_common import ComplexList
|
||||
from ansible.module_utils.netcli import Conditional
|
||||
from ansible.module_utils.six import string_types
|
||||
from ansible.module_utils.netcfg import NetworkConfig, dumps
|
||||
|
||||
SHARED_LIB = 'ios'
|
||||
|
||||
def get_ansible_module():
|
||||
if SHARED_LIB == 'ios':
|
||||
return LocalAnsibleModule
|
||||
return AnsibleModule
|
||||
|
||||
def invoke(name, *args, **kwargs):
|
||||
obj = globals().get(SHARED_LIB)
|
||||
func = getattr(obj, name)
|
||||
return func(*args, **kwargs)
|
||||
|
||||
load_config = partial(invoke, 'load_config')
|
||||
get_config = partial(invoke, 'get_config')
|
||||
|
||||
def check_args(module, warnings):
|
||||
if SHARED_LIB == 'ios_cli':
|
||||
ios_cli.check_args(module)
|
||||
|
||||
def get_current_config(module):
|
||||
if module.params['config']:
|
||||
return module.params['config']
|
||||
|
@ -174,23 +136,20 @@ def main():
|
|||
config=dict(),
|
||||
)
|
||||
|
||||
argument_spec.update(ios_cli.ios_cli_argument_spec)
|
||||
argument_spec.update(ios_argument_spec)
|
||||
|
||||
mutually_exclusive = [('config', 'backup'), ('config', 'force')]
|
||||
|
||||
cls = get_ansible_module()
|
||||
module = cls(argument_spec=argument_spec,
|
||||
mutually_exclusive=mutually_exclusive,
|
||||
supports_check_mode=True)
|
||||
|
||||
warnings = list()
|
||||
check_args(module, warnings)
|
||||
module = AnsibleModule(argument_spec=argument_spec,
|
||||
mutually_exclusive=mutually_exclusive,
|
||||
supports_check_mode=True)
|
||||
|
||||
candidate = NetworkConfig(contents=module.params['src'], indent=1)
|
||||
|
||||
result = {'changed': False}
|
||||
if warnings:
|
||||
result['warnings'] = warnings
|
||||
warnings = list()
|
||||
check_args(module, warnings)
|
||||
result['warnings'] = warnings
|
||||
|
||||
if module.params['backup']:
|
||||
result['__backup__'] = get_config(module=module)
|
||||
|
@ -210,9 +169,9 @@ def main():
|
|||
result['changed'] = True
|
||||
|
||||
result['updates'] = commands
|
||||
result['commands'] = commands
|
||||
|
||||
module.exit_json(**result)
|
||||
|
||||
if __name__ == '__main__':
|
||||
SHARED_LIB = 'ios_cli'
|
||||
main()
|
||||
|
|
|
@ -35,7 +35,6 @@ description:
|
|||
before returning or timing out if the condition is not met.
|
||||
- This module does not support running commands in configuration mode.
|
||||
Please use M(ios_config) to configure IOS devices.
|
||||
extends_documentation_fragment: ios
|
||||
options:
|
||||
commands:
|
||||
description:
|
||||
|
@ -129,52 +128,16 @@ failed_conditions:
|
|||
returned: failed
|
||||
type: list
|
||||
sample: ['...', '...']
|
||||
start:
|
||||
description: The time the job started
|
||||
returned: always
|
||||
type: str
|
||||
sample: "2016-11-16 10:38:15.126146"
|
||||
end:
|
||||
description: The time the job ended
|
||||
returned: always
|
||||
type: str
|
||||
sample: "2016-11-16 10:38:25.595612"
|
||||
delta:
|
||||
description: The time elapsed to perform all operations
|
||||
returned: always
|
||||
type: str
|
||||
sample: "0:00:10.469466"
|
||||
"""
|
||||
import time
|
||||
|
||||
from functools import partial
|
||||
|
||||
from ansible.module_utils import ios
|
||||
from ansible.module_utils import ios_cli
|
||||
from ansible.module_utils.ios import run_commands
|
||||
from ansible.module_utils.ios import ios_argument_spec, check_args
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.local import LocalAnsibleModule
|
||||
from ansible.module_utils.network_common import ComplexList
|
||||
from ansible.module_utils.netcli import Conditional
|
||||
from ansible.module_utils.six import string_types
|
||||
|
||||
SHARED_LIB = 'ios'
|
||||
|
||||
def get_ansible_module():
|
||||
if SHARED_LIB == 'ios':
|
||||
return LocalAnsibleModule
|
||||
return AnsibleModule
|
||||
|
||||
def invoke(name, *args, **kwargs):
|
||||
obj = globals().get(SHARED_LIB)
|
||||
func = getattr(obj, name)
|
||||
return func(*args, **kwargs)
|
||||
|
||||
run_commands = partial(invoke, 'run_commands')
|
||||
|
||||
def check_args(module, warnings):
|
||||
if SHARED_LIB == 'ios_cli':
|
||||
ios_cli.check_args(module)
|
||||
|
||||
def to_lines(stdout):
|
||||
for item in stdout:
|
||||
if isinstance(item, string_types):
|
||||
|
@ -215,17 +178,17 @@ def main():
|
|||
interval=dict(default=1, type='int')
|
||||
)
|
||||
|
||||
argument_spec.update(ios_cli.ios_cli_argument_spec)
|
||||
argument_spec.update(ios_argument_spec)
|
||||
|
||||
cls = get_ansible_module()
|
||||
module = cls(argument_spec=argument_spec, supports_check_mode=True)
|
||||
|
||||
warnings = list()
|
||||
check_args(module, warnings)
|
||||
module = AnsibleModule(argument_spec=argument_spec,
|
||||
supports_check_mode=True)
|
||||
|
||||
result = {'changed': False}
|
||||
|
||||
warnings = list()
|
||||
check_args(module, warnings)
|
||||
commands = parse_commands(module, warnings)
|
||||
result['warnings'] = warnings
|
||||
|
||||
wait_for = module.params['wait_for'] or list()
|
||||
conditionals = [Conditional(c) for c in wait_for]
|
||||
|
@ -259,7 +222,6 @@ def main():
|
|||
result = {
|
||||
'changed': False,
|
||||
'stdout': responses,
|
||||
'warnings': warnings,
|
||||
'stdout_lines': list(to_lines(responses))
|
||||
}
|
||||
|
||||
|
@ -267,5 +229,4 @@ def main():
|
|||
|
||||
|
||||
if __name__ == '__main__':
|
||||
SHARED_LIB = 'ios_cli'
|
||||
main()
|
||||
|
|
|
@ -33,7 +33,6 @@ description:
|
|||
for segmenting configuration into sections. This module provides
|
||||
an implementation for working with IOS configuration sections in
|
||||
a deterministic way.
|
||||
extends_documentation_fragment: ios
|
||||
options:
|
||||
lines:
|
||||
description:
|
||||
|
@ -202,31 +201,14 @@ backup_path:
|
|||
returned: when backup is yes
|
||||
type: path
|
||||
sample: /playbooks/ansible/backup/ios_config.2016-07-16@22:28:34
|
||||
start:
|
||||
description: The time the job started
|
||||
returned: always
|
||||
type: str
|
||||
sample: "2016-11-16 10:38:15.126146"
|
||||
end:
|
||||
description: The time the job ended
|
||||
returned: always
|
||||
type: str
|
||||
sample: "2016-11-16 10:38:25.595612"
|
||||
delta:
|
||||
description: The time elapsed to perform all operations
|
||||
returned: always
|
||||
type: str
|
||||
sample: "0:00:10.469466"
|
||||
"""
|
||||
import re
|
||||
import time
|
||||
|
||||
from functools import partial
|
||||
|
||||
from ansible.module_utils import ios
|
||||
from ansible.module_utils import ios_cli
|
||||
from ansible.module_utils.ios import run_commands, get_config, load_config
|
||||
from ansible.module_utils.ios import ios_argument_spec
|
||||
from ansible.module_utils.ios import check_args as ios_check_args
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.local import LocalAnsibleModule
|
||||
from ansible.module_utils.network_common import ComplexList
|
||||
from ansible.module_utils.netcli import Conditional
|
||||
from ansible.module_utils.six import string_types
|
||||
|
@ -234,26 +216,8 @@ from ansible.module_utils.netcfg import NetworkConfig, dumps
|
|||
from ansible.module_utils.six import iteritems
|
||||
|
||||
|
||||
SHARED_LIB = 'ios'
|
||||
|
||||
def get_ansible_module():
|
||||
if SHARED_LIB == 'ios':
|
||||
return LocalAnsibleModule
|
||||
return AnsibleModule
|
||||
|
||||
def invoke(name, *args, **kwargs):
|
||||
obj = globals().get(SHARED_LIB)
|
||||
func = getattr(obj, name)
|
||||
return func(*args, **kwargs)
|
||||
|
||||
run_commands = partial(invoke, 'run_commands')
|
||||
load_config = partial(invoke, 'load_config')
|
||||
get_config = partial(invoke, 'get_config')
|
||||
|
||||
def check_args(module, warnings):
|
||||
if SHARED_LIB == 'ios_cli':
|
||||
ios_cli.check_args(module)
|
||||
|
||||
ios_check_args(module, warnings)
|
||||
if module.params['multiline_delimiter']:
|
||||
if len(module.params['multiline_delimiter']) != 1:
|
||||
module.fail_json(msg='multiline_delimiter value can only be a '
|
||||
|
@ -350,7 +314,7 @@ def main():
|
|||
save=dict(type='bool', default=False),
|
||||
)
|
||||
|
||||
argument_spec.update(ios_cli.ios_cli_argument_spec)
|
||||
argument_spec.update(ios_argument_spec)
|
||||
|
||||
mutually_exclusive = [('lines', 'src')]
|
||||
|
||||
|
@ -358,22 +322,19 @@ def main():
|
|||
('match', 'exact', ['lines']),
|
||||
('replace', 'block', ['lines'])]
|
||||
|
||||
cls = get_ansible_module()
|
||||
module = cls(argument_spec=argument_spec,
|
||||
mutually_exclusive=mutually_exclusive,
|
||||
required_if=required_if,
|
||||
supports_check_mode=True)
|
||||
|
||||
warnings = list()
|
||||
check_args(module, warnings)
|
||||
module = AnsibleModule(argument_spec=argument_spec,
|
||||
mutually_exclusive=mutually_exclusive,
|
||||
required_if=required_if,
|
||||
supports_check_mode=True)
|
||||
|
||||
if module.params['force'] is True:
|
||||
module.params['match'] = 'none'
|
||||
|
||||
result = {'changed': False}
|
||||
|
||||
warnings = list()
|
||||
check_args(module, warnings)
|
||||
|
||||
result = {'changed': False, 'warnings': warnings}
|
||||
result['warnings'] = warnings
|
||||
|
||||
if any((module.params['lines'], module.params['src'])):
|
||||
match = module.params['match']
|
||||
|
@ -403,7 +364,7 @@ def main():
|
|||
if module.params['after']:
|
||||
commands.extend(module.params['after'])
|
||||
|
||||
result['updates'] = commands
|
||||
result['commands'] = commands
|
||||
result['banners'] = banners
|
||||
|
||||
# send the configuration commands to the device and merge
|
||||
|
@ -428,5 +389,4 @@ def main():
|
|||
|
||||
|
||||
if __name__ == '__main__':
|
||||
SHARED_LIB = 'ios_cli'
|
||||
main()
|
||||
|
|
|
@ -33,7 +33,6 @@ description:
|
|||
base network fact keys with C(ansible_net_<fact>). The facts
|
||||
module will always collect a base set of facts from the device
|
||||
and can enable or disable collection of additional facts.
|
||||
extends_documentation_fragment: ios
|
||||
options:
|
||||
gather_subset:
|
||||
description:
|
||||
|
@ -143,33 +142,12 @@ ansible_net_neighbors:
|
|||
"""
|
||||
import re
|
||||
|
||||
from functools import partial
|
||||
|
||||
from ansible.module_utils import ios
|
||||
from ansible.module_utils import ios_cli
|
||||
from ansible.module_utils.ios import run_commands
|
||||
from ansible.module_utils.ios import ios_argument_spec, check_args
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.local import LocalAnsibleModule
|
||||
from ansible.module_utils.six import iteritems
|
||||
from ansible.module_utils.six.moves import zip
|
||||
|
||||
SHARED_LIB = 'ios'
|
||||
|
||||
def get_ansible_module():
|
||||
if SHARED_LIB == 'ios':
|
||||
return LocalAnsibleModule
|
||||
return AnsibleModule
|
||||
|
||||
def invoke(name, *args, **kwargs):
|
||||
obj = globals().get(SHARED_LIB)
|
||||
func = getattr(obj, name)
|
||||
return func(*args, **kwargs)
|
||||
|
||||
run_commands = partial(invoke, 'run_commands')
|
||||
|
||||
def check_args(module, warnings):
|
||||
if SHARED_LIB == 'ios_cli':
|
||||
ios_cli.check_args(module)
|
||||
|
||||
|
||||
class FactsBase(object):
|
||||
|
||||
|
@ -443,13 +421,10 @@ def main():
|
|||
gather_subset=dict(default=['!config'], type='list')
|
||||
)
|
||||
|
||||
argument_spec.update(ios_cli.ios_cli_argument_spec)
|
||||
argument_spec.update(ios_argument_spec)
|
||||
|
||||
cls = get_ansible_module()
|
||||
module = cls(argument_spec=argument_spec, supports_check_mode=True)
|
||||
|
||||
warnings = list()
|
||||
check_args(module, warnings)
|
||||
module = AnsibleModule(argument_spec=argument_spec,
|
||||
supports_check_mode=True)
|
||||
|
||||
gather_subset = module.params['gather_subset']
|
||||
|
||||
|
@ -500,9 +475,11 @@ def main():
|
|||
key = 'ansible_net_%s' % key
|
||||
ansible_facts[key] = value
|
||||
|
||||
module.exit_json(ansible_facts=ansible_facts)
|
||||
warnings = list()
|
||||
check_args(module, warnings)
|
||||
|
||||
module.exit_json(ansible_facts=ansible_facts, warnings=warnings)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
SHARED_LIB = 'ios_cli'
|
||||
main()
|
||||
|
|
|
@ -126,26 +126,12 @@ commands:
|
|||
sample:
|
||||
- hostname ios01
|
||||
- ip domain name eng.ansible.com
|
||||
start:
|
||||
description: The time the job started
|
||||
returned: always
|
||||
type: str
|
||||
sample: "2016-11-16 10:38:15.126146"
|
||||
end:
|
||||
description: The time the job ended
|
||||
returned: always
|
||||
type: str
|
||||
sample: "2016-11-16 10:38:25.595612"
|
||||
delta:
|
||||
description: The time elapsed to perform all operations
|
||||
returned: always
|
||||
type: str
|
||||
sample: "0:00:10.469466"
|
||||
"""
|
||||
import re
|
||||
|
||||
from ansible.module_utils.local import LocalAnsibleModule
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.ios import get_config, load_config
|
||||
from ansible.module_utils.ios import ios_argument_spec, check_args
|
||||
from ansible.module_utils.network_common import ComplexList
|
||||
|
||||
_CONFIGURED_VRFS = None
|
||||
|
@ -364,11 +350,17 @@ def main():
|
|||
state=dict(choices=['present', 'absent'], default='present')
|
||||
)
|
||||
|
||||
module = LocalAnsibleModule(argument_spec=argument_spec,
|
||||
supports_check_mode=True)
|
||||
argument_spec.update(ios_argument_spec)
|
||||
|
||||
module = AnsibleModule(argument_spec=argument_spec,
|
||||
supports_check_mode=True)
|
||||
|
||||
result = {'changed': False}
|
||||
|
||||
warnings = list()
|
||||
check_args(module, warnings)
|
||||
result['warnings'] = warnings
|
||||
|
||||
want = map_params_to_obj(module)
|
||||
have = map_config_to_obj(module)
|
||||
|
||||
|
|
|
@ -142,8 +142,9 @@ import re
|
|||
|
||||
from functools import partial
|
||||
|
||||
from ansible.module_utils.local import LocalAnsibleModule
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.ios import load_config, get_config
|
||||
from ansible.module_utils.ios import ios_argument_spec, check_args
|
||||
from ansible.module_utils.netcfg import NetworkConfig
|
||||
from ansible.module_utils.six import iteritems
|
||||
|
||||
|
@ -327,14 +328,20 @@ def main():
|
|||
state=dict(default='present', choices=['present', 'absent'])
|
||||
)
|
||||
|
||||
argument_spec.update(ios_argument_spec)
|
||||
|
||||
mutually_exclusive = [('name', 'vrfs')]
|
||||
|
||||
module = LocalAnsibleModule(argument_spec=argument_spec,
|
||||
mutually_exclusive=mutually_exclusive,
|
||||
supports_check_mode=True)
|
||||
module = AnsibleModule(argument_spec=argument_spec,
|
||||
mutually_exclusive=mutually_exclusive,
|
||||
supports_check_mode=True)
|
||||
|
||||
result = {'changed': False}
|
||||
|
||||
warnings = list()
|
||||
check_args(module, warnings)
|
||||
result['warnings'] = warnings
|
||||
|
||||
want = map_params_to_obj(module)
|
||||
have = map_config_to_obj(module)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue