fixes bug where nxos_config wasn't handling checkpoints correctly
This commit is contained in:
parent
db18577df1
commit
ec9f6594ca
1 changed files with 16 additions and 7 deletions
|
@ -245,7 +245,7 @@ def get_config(module, result):
|
||||||
contents = module.config.get_config(include_defaults=defaults)
|
contents = module.config.get_config(include_defaults=defaults)
|
||||||
result[key] = contents
|
result[key] = contents
|
||||||
|
|
||||||
return NetworkConfig(indent=1, contents=contents)
|
return NetworkConfig(indent=2, contents=contents)
|
||||||
|
|
||||||
def backup_config(module, result):
|
def backup_config(module, result):
|
||||||
if '__config__' not in result:
|
if '__config__' not in result:
|
||||||
|
@ -254,15 +254,13 @@ def backup_config(module, result):
|
||||||
|
|
||||||
def load_config(module, commands, result):
|
def load_config(module, commands, result):
|
||||||
if not module.check_mode:
|
if not module.check_mode:
|
||||||
checkpoint = 'ansible_%s' % int(time.time())
|
|
||||||
module.cli(['checkpoint %s' % checkpoint], output='text')
|
|
||||||
result['__checkpoint__'] = checkpoint
|
|
||||||
module.config.load_config(commands)
|
module.config.load_config(commands)
|
||||||
result['changed'] = True
|
result['changed'] = True
|
||||||
|
|
||||||
def load_checkpoint(module, result):
|
def load_checkpoint(module, result):
|
||||||
try:
|
try:
|
||||||
checkpoint = result['__checkpoint__']
|
checkpoint = result['__checkpoint__']
|
||||||
|
module.log('load checkpoint %s' % checkpoint)
|
||||||
module.cli(['rollback running-config checkpoint %s' % checkpoint,
|
module.cli(['rollback running-config checkpoint %s' % checkpoint,
|
||||||
'no checkpoint %s' % checkpoint], output='text')
|
'no checkpoint %s' % checkpoint], output='text')
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
@ -281,7 +279,9 @@ def run(module, result):
|
||||||
|
|
||||||
if match != 'none':
|
if match != 'none':
|
||||||
config = get_config(module, result)
|
config = get_config(module, result)
|
||||||
configobjs = candidate.difference(config, match=match, replace=replace)
|
path = module.params['parents']
|
||||||
|
configobjs = candidate.difference(config, path=path, match=match,
|
||||||
|
replace=replace)
|
||||||
else:
|
else:
|
||||||
config = None
|
config = None
|
||||||
configobjs = candidate.items
|
configobjs = candidate.items
|
||||||
|
@ -291,7 +291,6 @@ def run(module, result):
|
||||||
|
|
||||||
if configobjs:
|
if configobjs:
|
||||||
commands = dumps(configobjs, 'commands').split('\n')
|
commands = dumps(configobjs, 'commands').split('\n')
|
||||||
result['updates'] = commands
|
|
||||||
|
|
||||||
if module.params['before']:
|
if module.params['before']:
|
||||||
commands[:0] = module.params['before']
|
commands[:0] = module.params['before']
|
||||||
|
@ -299,6 +298,15 @@ def run(module, result):
|
||||||
if module.params['after']:
|
if module.params['after']:
|
||||||
commands.extend(module.params['after'])
|
commands.extend(module.params['after'])
|
||||||
|
|
||||||
|
result['updates'] = commands
|
||||||
|
|
||||||
|
# create a checkpoint of the current running config in case
|
||||||
|
# there is a problem loading the candidate config
|
||||||
|
checkpoint = 'ansible_%s' % int(time.time())
|
||||||
|
module.cli(['checkpoint %s' % checkpoint], output='text')
|
||||||
|
result['__checkpoint__'] = checkpoint
|
||||||
|
module.log('create checkpoint %s' % checkpoint)
|
||||||
|
|
||||||
# if the update mode is set to check just return
|
# if the update mode is set to check just return
|
||||||
# and do not try to load into the system
|
# and do not try to load into the system
|
||||||
if update != 'check':
|
if update != 'check':
|
||||||
|
@ -307,7 +315,8 @@ def run(module, result):
|
||||||
# remove the checkpoint file used to restore the config
|
# remove the checkpoint file used to restore the config
|
||||||
# in case of an error
|
# in case of an error
|
||||||
if not module.check_mode:
|
if not module.check_mode:
|
||||||
module.cli('no checkpoint %s' % result['__checkpoint__'])
|
module.log('remove checkpoint %s' % checkpoint)
|
||||||
|
module.cli('no checkpoint %s' % checkpoint, output='text')
|
||||||
|
|
||||||
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()
|
||||||
|
|
Loading…
Reference in a new issue