def check_args(module, warnings): nxos_check_args(module, warnings) for key in ('include_defaults', 'config', 'save'): if module.params[key] is not None: warnings.append( 'argument %s is no longer supported, ignoring value' % key)
def check_args(module, warnings): provider = module.params['provider'] if provider['transport'] == 'nxapi': module.fail_json(msg='module not supported over nxapi transport') nxos_check_args(module, warnings) state = module.params['state'] if state == 'started': module.params['state'] = 'present' warnings.append('state=started is deprecated and will be removed in a ' 'a future release. Please use state=present instead') elif state == 'stopped': module.params['state'] = 'absent' warnings.append('state=stopped is deprecated and will be removed in a ' 'a future release. Please use state=absent instead') for key in ['config']: if module.params[key]: warnings.append('argument %s is deprecated and will be ignored' % key) for key in ['http_port', 'https_port']: if module.params[key] is not None: if not 1 <= module.params[key] <= 65535: module.fail_json(msg='%s must be between 1 and 65535' % key) return warnings
def check_args(module, warnings): transport = module.params['transport'] provider_transport = (module.params['provider'] or {}).get('transport') if 'nxapi' in (transport, provider_transport): module.fail_json( msg='transport=nxapi is not supporting when configuring nxapi') nxos_check_args(module, warnings) state = module.params['state'] if state == 'started': module.params['state'] = 'present' warnings.append('state=started is deprecated and will be removed in a ' 'a future release. Please use state=present instead') elif state == 'stopped': module.params['state'] = 'absent' warnings.append('state=stopped is deprecated and will be removed in a ' 'a future release. Please use state=absent instead') if module.params['transport'] == 'nxapi': module.fail_json(msg='module not supported over nxapi transport') for key in ['config']: if module.params[key]: warnings.append('argument %s is deprecated and will be ignored' % key) return warnings
def check_args(module, warnings): transport = module.params['transport'] provider_transport = (module.params['provider'] or {}).get('transport') if 'nxapi' in (transport, provider_transport): module.fail_json(msg='transport=nxapi is not supporting when configuring nxapi') nxos_check_args(module, warnings) state = module.params['state'] if state == 'started': module.params['state'] = 'present' warnings.append('state=started is deprecated and will be removed in a ' 'a future release. Please use state=present instead') elif state == 'stopped': module.params['state'] = 'absent' warnings.append('state=stopped is deprecated and will be removed in a ' 'a future release. Please use state=absent instead') if module.params['transport'] == 'nxapi': module.fail_json(msg='module not supported over nxapi transport') for key in ['config']: if module.params[key]: warnings.append('argument %s is deprecated and will be ignored' % key) for key in ['http_port', 'https_port']: if module.params[key] is not None: if not 1 <= module.params[key] <= 65535: module.fail_json(msg='%s must be between 1 and 65535' % key) return warnings
def check_args(module, warnings): nxos_check_args(module, warnings) if module.params['force']: warnings.append('The force argument is deprecated, please use ' 'match=none instead. This argument will be ' 'removed in the future')
def main(): """ main entry point for module execution """ argument_spec = dict( src=dict(type='path'), lines=dict(aliases=['commands'], type='list'), parents=dict(type='list'), before=dict(type='list'), after=dict(type='list'), match=dict(default='line', choices=['line', 'strict', 'exact', 'none']), replace=dict(default='line', choices=['line', 'block']), running_config=dict(aliases=['config']), intended_config=dict(), defaults=dict(type='bool', default=False), backup=dict(type='bool', default=False), save_when=dict(choices=['always', 'never', 'modified'], default='never'), diff_against=dict(choices=['running', 'startup', 'intended']), diff_ignore_lines=dict(type='list'), # save is deprecated as of ans2.4, use save_when instead save=dict(default=False, type='bool', removed_in_version='2.4'), # force argument deprecated in ans2.2 force=dict(default=False, type='bool', removed_in_version='2.2')) argument_spec.update(nxos_argument_spec) mutually_exclusive = [('lines', 'src'), ('save', 'save_when')] required_if = [('match', 'strict', ['lines']), ('match', 'exact', ['lines']), ('replace', 'block', ['lines']), ('diff_against', 'intended', ['intended_config'])] module = AnsibleModule(argument_spec=argument_spec, mutually_exclusive=mutually_exclusive, required_if=required_if, supports_check_mode=True) warnings = list() nxos_check_args(module, warnings) result = {'changed': False, 'warnings': warnings} config = None if module.params['backup'] or (module._diff and module.params['diff_against'] == 'running'): contents = get_config(module) config = NetworkConfig(indent=2, contents=contents) if module.params['backup']: result['__backup__'] = contents if any((module.params['src'], module.params['lines'])): match = module.params['match'] replace = module.params['replace'] candidate = get_candidate(module) if match != 'none': config = get_running_config(module, config) path = module.params['parents'] configobjs = candidate.difference(config, match=match, replace=replace, path=path) else: configobjs = candidate.items if configobjs: commands = dumps(configobjs, 'commands').split('\n') if module.params['before']: commands[:0] = module.params['before'] if module.params['after']: commands.extend(module.params['after']) result['commands'] = commands result['updates'] = commands if not module.check_mode: load_config(module, commands) result['changed'] = True running_config = None startup_config = None diff_ignore_lines = module.params['diff_ignore_lines'] if module.params['save']: module.params['save_when'] = 'always' if module.params['save_when'] != 'never': output = run_commands(module, ['show running-config', 'show startup-config']) running_config = NetworkConfig(indent=1, contents=output[0], ignore_lines=diff_ignore_lines) startup_config = NetworkConfig(indent=1, contents=output[1], ignore_lines=diff_ignore_lines) if running_config.sha1 != startup_config.sha1 or module.params[ 'save_when'] == 'always': result['changed'] = True if not module.check_mode: cmd = { 'command': 'copy running-config startup-config', 'output': 'text' } run_commands(module, [cmd]) else: module.warn( 'Skipping command `copy running-config startup-config` ' 'due to check_mode. Configuration not copied to ' 'non-volatile storage') if module._diff: if not running_config: output = run_commands(module, 'show running-config') contents = output[0] else: contents = running_config.config_text # recreate the object in order to process diff_ignore_lines running_config = NetworkConfig(indent=1, contents=contents, ignore_lines=diff_ignore_lines) if module.params['diff_against'] == 'running': if module.check_mode: module.warn( "unable to perform diff against running-config due to check mode" ) contents = None else: contents = config.config_text elif module.params['diff_against'] == 'startup': if not startup_config: output = run_commands(module, 'show startup-config') contents = output[0] else: contents = output[0] contents = startup_config.config_text elif module.params['diff_against'] == 'intended': contents = module.params['intended_config'] if contents is not None: base_config = NetworkConfig(indent=1, contents=contents, ignore_lines=diff_ignore_lines) if running_config.sha1 != base_config.sha1: result.update({ 'changed': True, 'diff': { 'before': str(base_config), 'after': str(running_config) } }) module.exit_json(**result)
def check_args(module, warnings): nxos_check_args(module, warnings) for key in ('include_defaults', 'config', 'save'): if module.params[key] is not None: warnings.append('argument %s is no longer supported, ignoring value' % key)
def main(): """ main entry point for module execution """ argument_spec = dict( src=dict(type='path'), lines=dict(aliases=['commands'], type='list'), parents=dict(type='list'), before=dict(type='list'), after=dict(type='list'), match=dict(default='line', choices=['line', 'strict', 'exact', 'none']), replace=dict(default='line', choices=['line', 'block']), running_config=dict(aliases=['config']), intended_config=dict(), defaults=dict(type='bool', default=False), backup=dict(type='bool', default=False), save_when=dict(choices=['always', 'never', 'modified'], default='never'), diff_against=dict(choices=['running', 'startup', 'intended']), diff_ignore_lines=dict(type='list'), # save is deprecated as of ans2.4, use save_when instead save=dict(default=False, type='bool', removed_in_version='2.4'), # force argument deprecated in ans2.2 force=dict(default=False, type='bool', removed_in_version='2.2') ) argument_spec.update(nxos_argument_spec) mutually_exclusive = [('lines', 'src'), ('save', 'save_when')] required_if = [('match', 'strict', ['lines']), ('match', 'exact', ['lines']), ('replace', 'block', ['lines']), ('diff_against', 'intended', ['intended_config'])] module = AnsibleModule(argument_spec=argument_spec, mutually_exclusive=mutually_exclusive, required_if=required_if, supports_check_mode=True) warnings = list() nxos_check_args(module, warnings) result = {'changed': False, 'warnings': warnings} config = None if module.params['backup'] or (module._diff and module.params['diff_against'] == 'running'): contents = get_config(module) config = NetworkConfig(indent=2, contents=contents) if module.params['backup']: result['__backup__'] = contents if any((module.params['src'], module.params['lines'])): match = module.params['match'] replace = module.params['replace'] candidate = get_candidate(module) if match != 'none': config = get_running_config(module, config) path = module.params['parents'] configobjs = candidate.difference(config, match=match, replace=replace, path=path) else: configobjs = candidate.items if configobjs: commands = dumps(configobjs, 'commands').split('\n') if module.params['before']: commands[:0] = module.params['before'] if module.params['after']: commands.extend(module.params['after']) result['commands'] = commands result['updates'] = commands if not module.check_mode: load_config(module, commands) result['changed'] = True running_config = None startup_config = None diff_ignore_lines = module.params['diff_ignore_lines'] if module.params['save']: module.params['save_when'] = 'always' if module.params['save_when'] != 'never': output = run_commands(module, ['show running-config', 'show startup-config']) running_config = NetworkConfig(indent=1, contents=output[0], ignore_lines=diff_ignore_lines) startup_config = NetworkConfig(indent=1, contents=output[1], ignore_lines=diff_ignore_lines) if running_config.sha1 != startup_config.sha1 or module.params['save_when'] == 'always': result['changed'] = True if not module.check_mode: cmd = {'command': 'copy running-config startup-config', 'output': 'text'} run_commands(module, [cmd]) else: module.warn('Skipping command `copy running-config startup-config` ' 'due to check_mode. Configuration not copied to ' 'non-volatile storage') if module._diff: if not running_config: output = run_commands(module, 'show running-config') contents = output[0] else: contents = running_config.config_text # recreate the object in order to process diff_ignore_lines running_config = NetworkConfig(indent=1, contents=contents, ignore_lines=diff_ignore_lines) if module.params['diff_against'] == 'running': if module.check_mode: module.warn("unable to perform diff against running-config due to check mode") contents = None else: contents = config.config_text elif module.params['diff_against'] == 'startup': if not startup_config: output = run_commands(module, 'show startup-config') contents = output[0] else: contents = output[0] contents = startup_config.config_text elif module.params['diff_against'] == 'intended': contents = module.params['intended_config'] if contents is not None: base_config = NetworkConfig(indent=1, contents=contents, ignore_lines=diff_ignore_lines) if running_config.sha1 != base_config.sha1: result.update({ 'changed': True, 'diff': {'before': str(base_config), 'after': str(running_config)} }) module.exit_json(**result)