bugfix in eos_template for backing up config

eos_template would connect to the remote device to get the running config
for backup even if backup is not needed.
reviewable/pr18780/r1
Peter Sprygada 9 years ago
parent cf3287b312
commit 416dd73b09

@ -36,8 +36,7 @@ options:
file with config or a template that will be merged during file with config or a template that will be merged during
runtime. By default the task will search for the source runtime. By default the task will search for the source
file in role or playbook root folder in templates directory. file in role or playbook root folder in templates directory.
required: false required: true
default: null
force: force:
description: description:
- The force argument instructs the module to not consider the - The force argument instructs the module to not consider the
@ -46,7 +45,16 @@ options:
without first checking if already configured. without first checking if already configured.
required: false required: false
default: false default: false
choices: BOOLEANS choices: ['yes', 'no']
include_defaults:
description:
- By default when the M(eos_template) connects to the remote
device to retrieve the configuration it will issue the `show
running-config` command. If this option is set to True then
the issued command will be `show running-config all`
required: false
default: false
choices: ['yes', 'no']
backup: backup:
description: description:
- When this argument is configured true, the module will backup - When this argument is configured true, the module will backup
@ -55,7 +63,7 @@ options:
the root of the playbook directory. the root of the playbook directory.
required: false required: false
default: false default: false
choices: BOOLEANS choices: ['yes', 'no']
replace: replace:
description: description:
- This argument will cause the provided configuration to be replaced - This argument will cause the provided configuration to be replaced
@ -65,7 +73,7 @@ options:
is eapi. is eapi.
required: false required: false
default: false default: false
choice: BOOLEANS choices: ['yes', 'no']
config: config:
description: description:
- The module, by default, will connect to the remote device and - The module, by default, will connect to the remote device and
@ -136,7 +144,7 @@ def flatten(data, obj):
return obj return obj
def get_config(module): def get_config(module):
config = module.params['config'] or dict() config = module.params.get('config')
if not config and not module.params['force']: if not config and not module.params['force']:
config = module.config config = module.config
return config return config
@ -146,7 +154,7 @@ def main():
""" """
argument_spec = dict( argument_spec = dict(
src=dict(), src=dict(required=True),
force=dict(default=False, type='bool'), force=dict(default=False, type='bool'),
include_defaults=dict(default=False, type='bool'), include_defaults=dict(default=False, type='bool'),
backup=dict(default=False, type='bool'), backup=dict(default=False, type='bool'),
@ -167,9 +175,12 @@ def main():
candidate = module.parse_config(module.params['src']) candidate = module.parse_config(module.params['src'])
contents = get_config(module) contents = get_config(module)
result['_backup'] = module.config
if contents:
config = module.parse_config(contents) config = module.parse_config(contents)
result['_backup'] = contents
else:
config = dict()
commands = collections.OrderedDict() commands = collections.OrderedDict()
toplevel = [c.text for c in config] toplevel = [c.text for c in config]

Loading…
Cancel
Save