# Buggy code
def main():
    argument_spec = dict(
        checkpoint_file=dict(required=False),
        rollback_to=dict(required=False),
        include_defaults=dict(default=True),
        config=dict(),
        save=dict(type="bool", default=False),
    )

    argument_spec.update(nxos_argument_spec)

    module = AnsibleModule(
        argument_spec=argument_spec,
        mutually_exclusive=[["checkpoint_file", "rollback_to"]],
        supports_check_mode=False,
    )

    checkpoint_file = module.params["checkpoint_file"]
    rollback_to = module.params["rollback_to"]

    status = None
    filename = None
    changed = False
    try:
        if checkpoint_file:
            checkpoint(checkpoint_file, module)
            status = "checkpoint file created"
        elif rollback_to:
            rollback(rollback_to, module)
            status = "rollback executed"
        changed = True
        filename = rollback_to or checkpoint_file
    except ShellError:
        clie = get_exception()
        module.fail_json(msg=str(clie))

    module.exit_json(changed=changed, status=status, filename=filename)


# Traceback (NameError)
Vault password:

PLAY [DRF_vxlan] ***********************************************************************************************************************************************************************************

TASK [checkpoint : Get backup] *********************************************************************************************************************************************************************
ok: [s-leaf]

TASK [checkpoint : DEBUG] **************************************************************************************************************************************************************************
ok: [s-leaf] => {
"changed": false,
"msg": "user.2017.04.12.13.57.03"
}

TASK [checkpoint : Set Checkpoint] *****************************************************************************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: NameError: global name 'ShellError' is not defined
fatal: [s-leaf]: FAILED! => {"changed": false, "failed": true, "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_aK1Nz9/ansible_module_nxos_rollback.py\", line 186, in <module>\n    main()\n  File \"/tmp/ansible_aK1Nz9/ansible_module_nxos_rollback.py\", line 178, in main\n    except ShellError:\nNameError: global name 'ShellError' is not defined\n", "module_stdout": "", "msg": "MODULE FAILURE", "rc": 0}
to retry, use: --limit @/home/user/retry-files/site.retry

PLAY RECAP *****************************************************************************************************************************************************************************************
s-leaf : ok=2    changed=0    unreachable=0    failed=1

# Fixed code
def main():
    argument_spec = dict(
        checkpoint_file=dict(required=False),
        rollback_to=dict(required=False),
        include_defaults=dict(default=True),
        config=dict(),
        save=dict(type="bool", default=False),
    )

    argument_spec.update(nxos_argument_spec)

    module = AnsibleModule(
        argument_spec=argument_spec,
        mutually_exclusive=[["checkpoint_file", "rollback_to"]],
        supports_check_mode=False,
    )

    checkpoint_file = module.params["checkpoint_file"]
    rollback_to = module.params["rollback_to"]

    status = None
    filename = None
    changed = False

    if checkpoint_file:
        checkpoint(checkpoint_file, module)
        status = "checkpoint file created"
    elif rollback_to:
        rollback(rollback_to, module)
        status = "rollback executed"
    changed = True
    filename = rollback_to or checkpoint_file

    module.exit_json(changed=changed, status=status, filename=filename)