roll up of minor fixes in eos_config module
* fixes save argument to be type bool * now properly sets the changed returned flag based on diff * updates docstring RETURNS to add backup_path * removes unneeded state argument tested on EOS 4.15.4Fpull/4420/head
parent
7010a66638
commit
51613d4307
|
@ -153,16 +153,6 @@ options:
|
||||||
required: false
|
required: false
|
||||||
default: false
|
default: false
|
||||||
version_added: "2.2"
|
version_added: "2.2"
|
||||||
state:
|
|
||||||
description:
|
|
||||||
- The I(state) argument specifies the state of the config
|
|
||||||
file on the device. When set to present, the configuration
|
|
||||||
is updated based on the values of the module. When the value
|
|
||||||
is set to absent, the device startup config is erased.
|
|
||||||
required: true
|
|
||||||
default: present
|
|
||||||
choices: ['present', 'absent']
|
|
||||||
version_added: "2.2"
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
EXAMPLES = """
|
EXAMPLES = """
|
||||||
|
@ -209,6 +199,11 @@ updates:
|
||||||
returned: always
|
returned: always
|
||||||
type: list
|
type: list
|
||||||
sample: ['...', '...']
|
sample: ['...', '...']
|
||||||
|
backup_path:
|
||||||
|
description: The full path to the backup file
|
||||||
|
returned: when backup is yes
|
||||||
|
type: path
|
||||||
|
sample: /playbooks/ansible/backup/eos_config.2016-07-16@22:28:34
|
||||||
"""
|
"""
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
@ -216,11 +211,6 @@ from ansible.module_utils.netcfg import NetworkConfig, dumps
|
||||||
from ansible.module_utils.eos import NetworkModule, NetworkError
|
from ansible.module_utils.eos import NetworkModule, NetworkError
|
||||||
from ansible.module_utils.basic import get_exception
|
from ansible.module_utils.basic import get_exception
|
||||||
|
|
||||||
def invoke(name, *args, **kwargs):
|
|
||||||
func = globals().get(name)
|
|
||||||
if func:
|
|
||||||
return func(*args, **kwargs)
|
|
||||||
|
|
||||||
def check_args(module, warnings):
|
def check_args(module, warnings):
|
||||||
if module.params['save'] and module.check_mode:
|
if module.params['save'] and module.check_mode:
|
||||||
warnings.append('will not save configuration due to checkmode')
|
warnings.append('will not save configuration due to checkmode')
|
||||||
|
@ -278,9 +268,11 @@ def load_config(module, commands, result):
|
||||||
del result['__session__']
|
del result['__session__']
|
||||||
|
|
||||||
result['diff'] = dict(prepared=diff)
|
result['diff'] = dict(prepared=diff)
|
||||||
result['changed'] = not diff
|
|
||||||
|
|
||||||
def present(module, result):
|
if diff:
|
||||||
|
result['changed'] = True
|
||||||
|
|
||||||
|
def run(module, result):
|
||||||
match = module.params['match']
|
match = module.params['match']
|
||||||
replace = module.params['replace']
|
replace = module.params['replace']
|
||||||
update = module.params['update']
|
update = module.params['update']
|
||||||
|
@ -311,11 +303,6 @@ def present(module, result):
|
||||||
if module.params['save'] and not module.check_mode:
|
if module.params['save'] and not module.check_mode:
|
||||||
module.config.save_config()
|
module.config.save_config()
|
||||||
|
|
||||||
def absent(module, result):
|
|
||||||
if not module.check_mode:
|
|
||||||
module.cli('write erase')
|
|
||||||
result['changed'] = True
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
""" main entry point for module execution
|
""" main entry point for module execution
|
||||||
"""
|
"""
|
||||||
|
@ -342,9 +329,7 @@ def main():
|
||||||
config=dict(),
|
config=dict(),
|
||||||
defaults=dict(type='bool', default=False),
|
defaults=dict(type='bool', default=False),
|
||||||
|
|
||||||
save=dict(default=False),
|
save=dict(default=False, type='bool'),
|
||||||
|
|
||||||
state=dict(default='present', choices=['absent', 'present'])
|
|
||||||
)
|
)
|
||||||
|
|
||||||
mutually_exclusive = [('lines', 'src')]
|
mutually_exclusive = [('lines', 'src')]
|
||||||
|
@ -354,8 +339,6 @@ def main():
|
||||||
mutually_exclusive=mutually_exclusive,
|
mutually_exclusive=mutually_exclusive,
|
||||||
supports_check_mode=True)
|
supports_check_mode=True)
|
||||||
|
|
||||||
state = module.params['state']
|
|
||||||
|
|
||||||
if module.params['force'] is True:
|
if module.params['force'] is True:
|
||||||
module.params['match'] = 'none'
|
module.params['match'] = 'none'
|
||||||
|
|
||||||
|
@ -368,7 +351,7 @@ def main():
|
||||||
result['__backup__'] = backup_config(module, result)
|
result['__backup__'] = backup_config(module, result)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
invoke(state, module, result)
|
run(module, result)
|
||||||
except NetworkError:
|
except NetworkError:
|
||||||
exc = get_exception()
|
exc = get_exception()
|
||||||
module.fail_json(msg=str(exc))
|
module.fail_json(msg=str(exc))
|
||||||
|
|
Loading…
Reference in New Issue