Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions changelogs/fragments/checkpoint_auto.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
minor_changes:
- aoscx_checkpoint - add the C(auto) and C(auto_timeout) options to manage the
auto-checkpoint (confirmed commit) timer (the C(checkpoint auto <minutes>)
and C(checkpoint auto confirm) commands), so a risky change can be deployed
with an automatic rollback if it is not confirmed within the timer.
52 changes: 51 additions & 1 deletion plugins/modules/aoscx_checkpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,26 @@
type: str
required: false
default: startup-config
auto:
description: >
Manage the auto-checkpoint (confirmed commit) timer instead of copying a
configuration. C(start) arms the timer and takes an automatic rollback
checkpoint (the C(checkpoint auto <minutes>) command); if it is not
confirmed before the timer expires the switch automatically restores the
configuration. C(confirm) ends the timer and keeps the running
configuration (the C(checkpoint auto confirm) command). When set, the
C(source_config) and C(destination_config) options are ignored.
type: str
required: false
choices:
- start
- confirm
auto_timeout:
description: >
Auto-checkpoint timer interval in minutes (1-60). Required when C(auto)
is C(start).
type: int
required: false
"""

EXAMPLES = """
Expand All @@ -56,6 +76,15 @@
aoscx_checkpoint:
source_config: 'running-config'
destination_config: 'checkpoint_20200128'

- name: Arm the auto-checkpoint timer for 2 minutes before a risky change
aoscx_checkpoint:
auto: start
auto_timeout: 2

- name: Confirm the configuration and stop the auto-checkpoint timer
aoscx_checkpoint:
auto: confirm
"""

RETURN = r""" # """
Expand All @@ -70,17 +99,28 @@ def main():
module_args = dict(
source_config=dict(type="str", default="running-config"),
destination_config=dict(type="str", default="startup-config"),
auto=dict(type="str", required=False, choices=["start", "confirm"]),
auto_timeout=dict(type="int", required=False),
)
ansible_module = AnsibleModule(
argument_spec=module_args, supports_check_mode=True
argument_spec=module_args,
supports_check_mode=True,
required_if=[("auto", "start", ["auto_timeout"])],
)

# Get playbook's arguments
source_config = ansible_module.params["source_config"]
destination_config = ansible_module.params["destination_config"]
auto = ansible_module.params["auto"]
auto_timeout = ansible_module.params["auto_timeout"]

result = dict(changed=False)

if auto == "start" and auto_timeout not in range(1, 61):
ansible_module.fail_json(
msg="auto_timeout must be between 1 and 60 minutes"
)

if ansible_module.check_mode:
ansible_module.exit_json(**result)

Expand All @@ -100,6 +140,16 @@ def main():

# Create a Configuration Object
config = device.configuration()

# Auto-checkpoint (confirmed commit) timer management.
if auto is not None:
if auto == "start":
success = config.set_auto_checkpoint(auto_timeout)
else:
success = config.confirm_auto_checkpoint()
result["changed"] = success
ansible_module.exit_json(**result)

success = config.create_checkpoint(source_config, destination_config)

# Changed
Expand Down