def main(): argument_spec = dict( src=dict(type='path'), lines=dict(type='list'), match=dict(default='line', choices=['line', 'none']), comment=dict(default=DEFAULT_COMMENT), config=dict(), backup=dict(default=False, type='bool'), save=dict(default=False, type='bool'), ) mutually_exclusive = [('lines', 'src')] module = NetworkModule(argument_spec=argument_spec, connect_on_load=False, mutually_exclusive=mutually_exclusive, supports_check_mode=True) result = dict(changed=False) if module.params['backup']: result['__backup__'] = module.config.get_config() try: run(module, result) except NetworkError: exc = get_exception() module.fail_json(msg=str(exc), **exc.kwargs) module.exit_json(**result)
def do_rollback(module, result): rollback = 'rollback %s' % module.params['rollback'] prompt = re.compile('\[confirm\]') cmd = Command(rollback, prompt=prompt, response='y', is_reboot=True, delay=1) try: module.cli(['configure', cmd]) except NetworkError: exc = get_exception() cmds = [str(c) for c in exc.kwargs.get('commands', list())] module.fail_json(msg=str(exc), commands=cmds)