def run(module, result): # get the current active config from the node or passed in via # the config param config = module.params['config'] or get_config(module) # create the candidate config object from the arguments candidate = get_candidate(module) # create loadable config that includes only the configuration updates commands = diff_config(module, candidate, config) result['commands'] = commands commit = not module.check_mode comment = module.params['comment'] if commands: prepared_diff = {} prepared_diff['prepared'] = load_config(module, commands, commit=commit, comment=comment) result['diff'] = prepared_diff result['changed'] = True
def main(): backup_spec = dict( filename=dict(), dir_path=dict(type='path') ) 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(type='bool', default=False), backup_options=dict(type='dict', options=backup_spec), save=dict(type='bool', default=False), ) mutually_exclusive = [('lines', 'src')] module = AnsibleModule( argument_spec=spec, mutually_exclusive=mutually_exclusive, supports_check_mode=True ) warnings = list() result = dict(changed=False, warnings=warnings) if module.params['backup']: result['__backup__'] = get_config(module=module) if any((module.params['src'], module.params['lines'])): run(module, result) if module.params['save']: diff = run_commands(module, commands=['configure', 'compare saved'])[1] if diff != '[edit]': if 'commands' in result: result['commands'].append('save') if not module.check_mode: run_commands(module, commands=['save']) result['changed'] = True run_commands(module, commands=['exit']) module.exit_json(**result)