mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
fixup ios_template module to use NetworkModule
This removes the get_module() factory function and directly creates an instance of NetworkModule. This commit includes some minor clean up to transition to the ios shared module for 2.2
This commit is contained in:
parent
7515b2d563
commit
438b9328ea
1 changed files with 12 additions and 13 deletions
|
@ -19,7 +19,7 @@ DOCUMENTATION = """
|
||||||
---
|
---
|
||||||
module: ios_template
|
module: ios_template
|
||||||
version_added: "2.1"
|
version_added: "2.1"
|
||||||
author: "Peter sprygada (@privateip)"
|
author: "Peter Sprygada (@privateip)"
|
||||||
short_description: Manage Cisco IOS device configurations over SSH
|
short_description: Manage Cisco IOS device configurations over SSH
|
||||||
description:
|
description:
|
||||||
- Manages Cisco IOS network device configurations over SSH. This module
|
- Manages Cisco IOS network device configurations over SSH. This module
|
||||||
|
@ -115,11 +115,13 @@ responses:
|
||||||
type: list
|
type: list
|
||||||
sample: ['...', '...']
|
sample: ['...', '...']
|
||||||
"""
|
"""
|
||||||
|
from ansible.module_utils.netcfg import NetworkConfig, dumps
|
||||||
|
from ansible.module_utils.ios import NetworkModule, NetworkError
|
||||||
|
|
||||||
def get_config(module):
|
def get_config(module):
|
||||||
config = module.params['config'] or dict()
|
config = module.params['config'] or dict()
|
||||||
if not config and not module.params['force']:
|
if not config and not module.params['force']:
|
||||||
config = module.config
|
config = module.config.get_config()
|
||||||
return config
|
return config
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
@ -136,7 +138,7 @@ def main():
|
||||||
|
|
||||||
mutually_exclusive = [('config', 'backup'), ('config', 'force')]
|
mutually_exclusive = [('config', 'backup'), ('config', 'force')]
|
||||||
|
|
||||||
module = get_module(argument_spec=argument_spec,
|
module = NetworkModule(argument_spec=argument_spec,
|
||||||
mutually_exclusive=mutually_exclusive,
|
mutually_exclusive=mutually_exclusive,
|
||||||
supports_check_mode=True)
|
supports_check_mode=True)
|
||||||
|
|
||||||
|
@ -149,15 +151,16 @@ def main():
|
||||||
config = NetworkConfig(contents=contents, indent=1)
|
config = NetworkConfig(contents=contents, indent=1)
|
||||||
result['_backup'] = contents
|
result['_backup'] = contents
|
||||||
|
|
||||||
|
commands = list()
|
||||||
if not module.params['force']:
|
if not module.params['force']:
|
||||||
commands = candidate.difference(config)
|
commands = dumps(candidate.difference(config), 'commands')
|
||||||
else:
|
else:
|
||||||
commands = str(candidate).split('\n')
|
commands = str(candidate)
|
||||||
|
|
||||||
if commands:
|
if commands:
|
||||||
|
commands = commands.split('\n')
|
||||||
if not module.check_mode:
|
if not module.check_mode:
|
||||||
commands = [str(c).strip() for c in commands]
|
response = module.config(commands)
|
||||||
response = module.configure(commands)
|
|
||||||
result['responses'] = response
|
result['responses'] = response
|
||||||
result['changed'] = True
|
result['changed'] = True
|
||||||
|
|
||||||
|
@ -165,10 +168,6 @@ def main():
|
||||||
module.exit_json(**result)
|
module.exit_json(**result)
|
||||||
|
|
||||||
|
|
||||||
from ansible.module_utils.basic import *
|
|
||||||
from ansible.module_utils.shell import *
|
|
||||||
from ansible.module_utils.netcfg import *
|
|
||||||
from ansible.module_utils.ios import *
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue