mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-24 22:00: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
|
@ -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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue