Add backup parameter to cli_config (#50206)

* Add backup parameter to cli_config

* Add a unit test for cli_config backup
This commit is contained in:
Nathaniel Case 2018-12-21 09:55:14 -05:00 committed by GitHub
commit 0b3aa75b7f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 206 additions and 2 deletions

View file

@ -45,6 +45,17 @@ options:
Use I(net_put) or I(nxos_file_copy) module to copy the flat file
to remote device and then use set the fullpath to this argument.
type: 'str'
backup:
description:
- This argument will cause the module to create a full backup of
the current running config from the remote device before any
changes are made. The backup file is written to the C(backup)
folder in the playbook root directory or role root directory, if
playbook is part of an ansible role. If the directory does not exist,
it is created.
type: bool
default: 'no'
version_added: "2.8"
rollback:
description:
- The C(rollback) argument instructs the module to rollback the
@ -140,6 +151,11 @@ commands:
returned: always
type: list
sample: ['interface Loopback999', 'no shutdown']
backup_path:
description: The full path to the backup file
returned: when backup is yes
type: str
sample: /playbooks/ansible/backup/hostname_config.2016-07-16@22:28:34
"""
import json
@ -284,6 +300,7 @@ def main():
"""main entry point for execution
"""
argument_spec = dict(
backup=dict(default=False, type='bool'),
config=dict(type='str'),
commit=dict(type='bool'),
replace=dict(type='str'),
@ -297,7 +314,7 @@ def main():
)
mutually_exclusive = [('config', 'rollback')]
required_one_of = [['config', 'rollback']]
required_one_of = [['backup', 'config', 'rollback']]
module = AnsibleModule(argument_spec=argument_spec,
mutually_exclusive=mutually_exclusive,
@ -323,6 +340,9 @@ def main():
candidate = to_text(module.params['config'])
running = connection.get_config(flags=flags)
if module.params['backup']:
result['__backup__'] = running
try:
result.update(run(module, capabilities, connection, candidate, running))
except Exception as exc: