def run(module, result): match = module.params['match'] replace = module.params['replace'] path = module.params['parents'] configobjs = None candidate = get_candidate(module) if match != 'none': contents = module.params['config'] if not contents: contents = get_config(module) config = NetworkConfig(indent=1, contents=contents) configobjs = candidate.difference(config, path=path, match=match, replace=replace) else: configobjs = candidate.items if configobjs: commands = dumps(configobjs, 'commands').split('\n') if module.params['lines']: if module.params['before']: commands[:0] = module.params['before'] if module.params['after']: commands.extend(module.params['after']) result['updates'] = commands # send the configuration commands to the device and merge # them with the current running config if not module.check_mode: load_config(module, commands) result['changed'] = True if result['changed'] or module.params['save_when'] == 'always': result['changed'] = True if not module.check_mode: cmd = {'command': 'write memory'} run_commands(module, [cmd])