def main(): """ main entry point for module execution """ element_spec = dict( name=dict(type="str"), description=dict(type="str"), speed=dict(choices=["10", "100", "1000"]), mtu=dict(), duplex=dict(choices=["full", "half"]), enabled=dict(default=True, type="bool"), active=dict(default="active", type="str", choices=["active", "preconfigure"]), tx_rate=dict(), rx_rate=dict(), delay=dict(default=10, type="int"), state=dict(default="present", choices=["present", "absent", "up", "down"]), ) aggregate_spec = deepcopy(element_spec) aggregate_spec["name"] = dict(required=True) # remove default in aggregate spec, to handle common arguments remove_default_spec(aggregate_spec) argument_spec = dict( aggregate=dict(type="list", elements="dict", options=aggregate_spec)) argument_spec.update(element_spec) argument_spec.update(iosxr_argument_spec) required_one_of = [["name", "aggregate"]] mutually_exclusive = [["name", "aggregate"]] module = AnsibleModule( argument_spec=argument_spec, required_one_of=required_one_of, mutually_exclusive=mutually_exclusive, supports_check_mode=True, ) config_object = None if is_cliconf(module): # Commenting the below cliconf deprecation support call for Ansible 2.9 as it'll be continued to be supported # module.deprecate("cli support for 'iosxr_interface' is deprecated. Use transport netconf instead", # version='2.9') config_object = CliConfiguration(module) elif is_netconf(module): if module.params["active"] == "preconfigure": module.fail_json( msg= "Physical interface pre-configuration is not supported with transport 'netconf'" ) config_object = NCConfiguration(module) result = {} if config_object: result = config_object.run() module.exit_json(**result)
def main(): """ main entry point for module execution """ element_spec = dict( name=dict(), full_name=dict(), level=dict(aliases=["role"]), configured_password=dict(no_log=True), update_password=dict(default="always", choices=["on_create", "always"]), state=dict(default="present", choices=["present", "absent"]), ) aggregate_spec = deepcopy(element_spec) aggregate_spec["name"] = dict(required=True) # remove default in aggregate spec, to handle common arguments remove_default_spec(aggregate_spec) argument_spec = dict( aggregate=dict( type="list", elements="dict", options=aggregate_spec, aliases=["users", "collection"], ), purge=dict(type="bool", default=False), ) argument_spec.update(element_spec) argument_spec.update(vyos_argument_spec) mutually_exclusive = [("name", "aggregate")] module = AnsibleModule( argument_spec=argument_spec, mutually_exclusive=mutually_exclusive, supports_check_mode=True, ) warnings = list() result = {"changed": False, "warnings": warnings} want = map_params_to_obj(module) have = config_to_dict(module) commands = spec_to_commands(update_objects(want, have), module) if module.params["purge"]: want_users = [x["name"] for x in want] have_users = [x["name"] for x in have] for item in set(have_users).difference(want_users): commands.append("delete system login user %s" % item) result["commands"] = commands if commands: commit = not module.check_mode load_config(module, commands, commit=commit) result["changed"] = True module.exit_json(**result)
def main(): """ main entry point for module execution """ element_spec = dict( name=dict(), full_name=dict(), role=dict(choices=ROLES), encrypted_password=dict(no_log=True), sshkey=dict(), state=dict(choices=['present', 'absent'], default='present'), active=dict(type='bool', default=True) ) aggregate_spec = deepcopy(element_spec) aggregate_spec['name'] = dict(required=True) # remove default in aggregate spec, to handle common arguments remove_default_spec(aggregate_spec) argument_spec = dict( aggregate=dict(type='list', elements='dict', options=aggregate_spec, aliases=['collection', 'users']), purge=dict(default=False, type='bool') ) argument_spec.update(element_spec) argument_spec.update(junos_argument_spec) mutually_exclusive = [['aggregate', 'name']] module = AnsibleModule(argument_spec=argument_spec, mutually_exclusive=mutually_exclusive, supports_check_mode=True) warnings = list() result = {'changed': False, 'warnings': warnings} want = map_params_to_obj(module) ele = map_obj_to_ele(module, want) purge_request = None if module.params['purge']: purge_request = handle_purge(module, want) with locked_config(module): if purge_request: load_config(module, tostring(purge_request), warnings, action='replace') diff = load_config(module, tostring(ele), warnings, action='merge') commit = not module.check_mode if diff: if commit: commit_configuration(module) else: discard_changes(module) result['changed'] = True if module._diff: result['diff'] = {'prepared': diff} module.exit_json(**result)
def main(): """main entry point for module execution""" element_spec = dict( name=dict(), interfaces=dict(type="list", elements="str"), associated_interfaces=dict(type="list", elements="str"), delay=dict(default=10, type="int"), rd=dict(), state=dict(default="present", choices=["present", "absent"]), ) aggregate_spec = deepcopy(element_spec) aggregate_spec["name"] = dict(required=True) # remove default in aggregate spec, to handle common arguments remove_default_spec(aggregate_spec) aggregate_spec["state"].update(default="present") aggregate_spec["delay"].update(default=10) argument_spec = dict( aggregate=dict(type="list", elements="dict", options=aggregate_spec), purge=dict(default=False, type="bool"), ) argument_spec.update(element_spec) argument_spec.update(eos_argument_spec) required_one_of = [["name", "aggregate"]] mutually_exclusive = [["name", "aggregate"]] module = AnsibleModule( argument_spec=argument_spec, required_one_of=required_one_of, mutually_exclusive=mutually_exclusive, supports_check_mode=True, ) warnings = list() result = {"changed": False} if warnings: result["warnings"] = warnings want = map_params_to_obj(module) have = map_config_to_obj(module) commands = map_obj_to_commands((want, have), module) result["commands"] = commands if commands: commit = not module.check_mode response = load_config(module, commands, commit=commit) if response.get("diff") and module._diff: result["diff"] = {"prepared": response.get("diff")} result["session_name"] = response.get("session") result["changed"] = True check_declarative_intent_params(want, module, result) module.exit_json(**result)
def main(): """ main entry point for module execution """ element_spec = dict( name=dict(type="str", aliases=["vrf"]), description=dict(type="str"), vni=dict(type="str"), rd=dict(type="str"), admin_state=dict(type="str", default="up", choices=["up", "down"]), interfaces=dict(type="list"), associated_interfaces=dict(type="list"), delay=dict(type="int", default=10), state=dict(type="str", default="present", choices=["present", "absent"]), ) aggregate_spec = deepcopy(element_spec) # remove default in aggregate spec, to handle common arguments remove_default_spec(aggregate_spec) argument_spec = dict( aggregate=dict(type="list", elements="dict", options=aggregate_spec), purge=dict(type="bool", default=False), ) argument_spec.update(element_spec) argument_spec.update(nxos_argument_spec) required_one_of = [["name", "aggregate"]] mutually_exclusive = [["name", "aggregate"]] module = AnsibleModule( argument_spec=argument_spec, required_one_of=required_one_of, mutually_exclusive=mutually_exclusive, supports_check_mode=True, ) warnings = list() result = {"changed": False} if warnings: result["warnings"] = warnings want = map_params_to_obj(module) have = map_config_to_obj(want, element_spec, module) commands = map_obj_to_commands((want, have), module) result["commands"] = commands if commands and not module.check_mode: responses = load_config(module, commands, opts={"catch_clierror": True}) vrf_error_check(module, commands, responses) result["changed"] = True check_declarative_intent_params(want, module, element_spec, result) module.exit_json(**result)
def _get_aggregate_spec(cls, element_spec): aggregate_spec = deepcopy(element_spec) aggregate_spec['vlan_id'] = dict(required=True) # remove default in aggregate spec, to handle common arguments remove_default_spec(aggregate_spec) return aggregate_spec
def main(): """ main entry point for module execution """ element_spec = dict( dest=dict(type='str', choices=['host', 'console', 'monitor', 'buffered', 'file']), name=dict(type='str'), size=dict(type='int'), vrf=dict(type='str', default='default'), facility=dict(type='str', default='local7'), hostnameprefix=dict(type='str'), level=dict(type='str', default='informational', aliases=['severity'], choices=[ 'emergencies', 'alerts', 'critical', 'errors', 'warning', 'notifications', 'informational', 'debugging' ]), state=dict(default='present', choices=['present', 'absent']), ) aggregate_spec = deepcopy(element_spec) # remove default in aggregate spec, to handle common arguments remove_default_spec(aggregate_spec) mutually_exclusive = [('dest', 'facility', 'hostnameprefix')] required_if = [('dest', 'host', ['name']), ('dest', 'file', ['name']), ('dest', 'buffered', ['size']), ('dest', 'console', ['level']), ('dest', 'monitor', ['level'])] argument_spec = dict(aggregate=dict(type='list', elements='dict', options=aggregate_spec, mutually_exclusive=mutually_exclusive, required_if=required_if), ) argument_spec.update(element_spec) argument_spec.update(iosxr_argument_spec) module = AnsibleModule(argument_spec=argument_spec, mutually_exclusive=mutually_exclusive, required_if=required_if, supports_check_mode=True) config_object = None if is_cliconf(module): # Commenting the below cliconf deprecation support call for Ansible 2.9 as it'll be continued to be supported # module.deprecate("cli support for 'iosxr_interface' is deprecated. Use transport netconf instead", # version='2.9') config_object = CliConfiguration(module) elif is_netconf(module): config_object = NCConfiguration(module) if config_object: result = config_object.run() module.exit_json(**result)
def main(): """ main entry point for module execution """ element_spec = dict( dest=dict( type='str', choices=['on', 'host', 'console', 'monitor', 'buffered', 'trap']), name=dict(type='str'), size=dict(type='int'), facility=dict(type='str'), level=dict(type='str', default='debugging', choices=[ 'emergencies', 'alerts', 'critical', 'errors', 'warnings', 'notifications', 'informational', 'debugging' ]), state=dict(default='present', choices=['present', 'absent']), ) aggregate_spec = deepcopy(element_spec) # remove default in aggregate spec, to handle common arguments remove_default_spec(aggregate_spec) argument_spec = dict(aggregate=dict(type='list', elements='dict', options=aggregate_spec), ) argument_spec.update(element_spec) argument_spec.update(ios_argument_spec) required_if = [('dest', 'host', ['name'])] module = AnsibleModule(argument_spec=argument_spec, required_if=required_if, supports_check_mode=True) device_info = get_capabilities(module) os_version = device_info['device_info']['network_os_version'] warnings = list() result = {'changed': False} if warnings: result['warnings'] = warnings want = map_params_to_obj(module, required_if=required_if) have = map_config_to_obj(module) commands = map_obj_to_commands((want, have), module, os_version) result['commands'] = commands if commands: if not module.check_mode: load_config(module, commands) result['changed'] = True module.exit_json(**result)
def main(): """ main entry point for module execution """ element_spec = dict( name=dict(), configured_password=dict(no_log=True), update_password=dict(default='always', choices=['on_create', 'always']), roles=dict(type='list', aliases=['role']), sshkey=dict(), state=dict(default='present', choices=['present', 'absent']) ) aggregate_spec = deepcopy(element_spec) # remove default in aggregate spec, to handle common arguments remove_default_spec(aggregate_spec) argument_spec = dict( aggregate=dict(type='list', elements='dict', options=aggregate_spec, aliases=['collection', 'users']), purge=dict(type='bool', default=False) ) argument_spec.update(element_spec) argument_spec.update(nxos_argument_spec) mutually_exclusive = [('name', 'aggregate')] module = AnsibleModule(argument_spec=argument_spec, mutually_exclusive=mutually_exclusive, supports_check_mode=True) result = {'changed': False} want = map_params_to_obj(module) have = map_config_to_obj(module) commands = map_obj_to_commands(update_objects(want, have), module) if module.params['purge']: want_users = [x['name'] for x in want] have_users = [x['name'] for x in have] for item in set(have_users).difference(want_users): if item != 'admin': item = item.replace("\\", "\\\\") commands.append('no username %s' % item) result['commands'] = commands # the nxos cli prevents this by rule so capture it and display # a nice failure message if 'no username admin' in commands: module.fail_json(msg='cannot delete the `admin` account') if commands: if not module.check_mode: load_config(module, commands) result['changed'] = True module.exit_json(**result)
def main(): """ main entry point for module execution """ element_spec = dict( name=dict(type='str', aliases=['vrf']), description=dict(type='str'), vni=dict(type='str'), rd=dict(type='str'), admin_state=dict(type='str', default='up', choices=['up', 'down']), interfaces=dict(type='list'), associated_interfaces=dict(type='list'), delay=dict(type='int', default=10), state=dict(type='str', default='present', choices=['present', 'absent']), ) aggregate_spec = deepcopy(element_spec) # remove default in aggregate spec, to handle common arguments remove_default_spec(aggregate_spec) argument_spec = dict( aggregate=dict(type='list', elements='dict', options=aggregate_spec), purge=dict(type='bool', default=False), ) argument_spec.update(element_spec) argument_spec.update(nxos_argument_spec) required_one_of = [['name', 'aggregate']] mutually_exclusive = [['name', 'aggregate']] module = AnsibleModule(argument_spec=argument_spec, required_one_of=required_one_of, mutually_exclusive=mutually_exclusive, supports_check_mode=True) warnings = list() result = {'changed': False} if warnings: result['warnings'] = warnings want = map_params_to_obj(module) have = map_config_to_obj(want, element_spec, module) commands = map_obj_to_commands((want, have), module) result['commands'] = commands if commands and not module.check_mode: responses = load_config(module, commands, opts={'catch_clierror': True}) vrf_error_check(module, commands, responses) result['changed'] = True check_declarative_intent_params(want, module, element_spec, result) module.exit_json(**result)
def main(): """ main entry point for module execution """ element_spec = dict( group=dict(type="int"), mode=dict(choices=["active", "passive"]), members=dict(type="list"), state=dict(default="present", choices=["present", "absent"]), ) aggregate_spec = deepcopy(element_spec) aggregate_spec["group"] = dict(required=True) required_one_of = [["group", "aggregate"]] required_together = [["members", "mode"]] mutually_exclusive = [["group", "aggregate"]] # remove default in aggregate spec, to handle common arguments remove_default_spec(aggregate_spec) argument_spec = dict( aggregate=dict( type="list", elements="dict", options=aggregate_spec, required_together=required_together, ), purge=dict(default=False, type="bool"), ) argument_spec.update(element_spec) argument_spec.update(awplus_argument_spec) module = AnsibleModule( argument_spec=argument_spec, required_one_of=required_one_of, required_together=required_together, mutually_exclusive=mutually_exclusive, supports_check_mode=True, ) warnings = list() result = {"changed": False} if warnings: result["warnings"] = warnings want = map_params_to_obj(module) have = map_config_to_obj(module) commands = map_obj_to_commands((want, have), module) result["commands"] = commands if commands: if not module.check_mode: load_config(module, commands) result["changed"] = True module.exit_json(**result)
def main(): element_spec = dict(group=dict(type='int'), name=dict(type='str'), mode=dict(choices=['dynamic', 'static']), members=dict(type='list'), state=dict(default='present', choices=['present', 'absent']), check_running_config=dict( default=False, type='bool', fallback=(env_fallback, ['ANSIBLE_CHECK_ICX_RUNNING_CONFIG']))) aggregate_spec = deepcopy(element_spec) aggregate_spec['group'] = dict(required=True, type='int') required_one_of = [['group', 'aggregate']] required_together = [['name', 'group']] mutually_exclusive = [['group', 'aggregate']] remove_default_spec(aggregate_spec) argument_spec = dict(aggregate=dict(type='list', elements='dict', options=aggregate_spec, required_together=required_together), purge=dict(default=False, type='bool')) argument_spec.update(element_spec) module = AnsibleModule(argument_spec=argument_spec, required_one_of=required_one_of, required_together=required_together, mutually_exclusive=mutually_exclusive, supports_check_mode=True) warnings = list() result = {'changed': False} if warnings: result['warnings'] = warnings want = map_params_to_obj(module) if module.params['check_running_config'] is False: have = {} else: have = map_config_to_obj(module) commands = map_obj_to_commands((want, have), module) result["commands"] = commands if commands: if not module.check_mode: load_config(module, commands) result['changed'] = True module.exit_json(**result)
def main(): """ main entry point for module execution """ element_spec = dict(prefix=dict(type='str'), mask=dict(type='str'), next_hop=dict(type='str'), admin_distance=dict(type='int'), state=dict(default='present', choices=['present', 'absent']), check_running_config=dict( default=True, type='bool', fallback=(env_fallback, ['ANSIBLE_CHECK_ICX_RUNNING_CONFIG']))) aggregate_spec = deepcopy(element_spec) aggregate_spec['prefix'] = dict(required=True) remove_default_spec(aggregate_spec) argument_spec = dict(aggregate=dict(type='list', elements='dict', options=aggregate_spec), purge=dict(default=False, type='bool')) argument_spec.update(element_spec) required_one_of = [['aggregate', 'prefix']] required_together = [['prefix', 'next_hop']] mutually_exclusive = [['aggregate', 'prefix']] module = AnsibleModule(argument_spec=argument_spec, required_one_of=required_one_of, mutually_exclusive=mutually_exclusive, supports_check_mode=True) if not HAS_IPADDRESS: module.fail_json(msg="ipaddress python package is required") warnings = list() result = {'changed': False} if warnings: result['warnings'] = warnings want = map_params_to_obj(module, required_together=required_together) have = map_config_to_obj(module) commands = map_obj_to_commands(want, have, module) result['commands'] = commands if commands: if not module.check_mode: load_config(module, commands) result['changed'] = True module.exit_json(**result)
def main(): """ main entry point for module execution """ element_spec = dict(name=dict(type='str'), description=dict(type='str'), speed=dict(choices=['10', '100', '1000']), mtu=dict(), duplex=dict(choices=['full', 'half']), enabled=dict(default=True, type='bool'), active=dict(default='active', type='str', choices=['active', 'preconfigure']), tx_rate=dict(), rx_rate=dict(), delay=dict(default=10, type='int'), state=dict(default='present', choices=['present', 'absent', 'up', 'down'])) aggregate_spec = deepcopy(element_spec) aggregate_spec['name'] = dict(required=True) # remove default in aggregate spec, to handle common arguments remove_default_spec(aggregate_spec) argument_spec = dict(aggregate=dict(type='list', elements='dict', options=aggregate_spec), ) argument_spec.update(element_spec) argument_spec.update(iosxr_argument_spec) required_one_of = [['name', 'aggregate']] mutually_exclusive = [['name', 'aggregate']] module = AnsibleModule(argument_spec=argument_spec, required_one_of=required_one_of, mutually_exclusive=mutually_exclusive, supports_check_mode=True) config_object = None if is_cliconf(module): # Commenting the below cliconf deprecation support call for Ansible 2.9 as it'll be continued to be supported # module.deprecate("cli support for 'iosxr_interface' is deprecated. Use transport netconf instead", # version='2.9') config_object = CliConfiguration(module) elif is_netconf(module): if module.params['active'] == 'preconfigure': module.fail_json( msg= "Physical interface pre-configuration is not supported with transport 'netconf'" ) config_object = NCConfiguration(module) result = {} if config_object: result = config_object.run() module.exit_json(**result)
def main(): """ main entry point for module execution """ element_spec = dict(name=dict(), interfaces=dict(type='list'), associated_interfaces=dict(type='list'), delay=dict(default=10, type='int'), rd=dict(), state=dict(default='present', choices=['present', 'absent'])) aggregate_spec = deepcopy(element_spec) # remove default in aggregate spec, to handle common arguments remove_default_spec(aggregate_spec) argument_spec = dict(aggregate=dict(type='list', elements='dict', options=aggregate_spec), purge=dict(default=False, type='bool')) argument_spec.update(element_spec) required_one_of = [['name', 'aggregate']] mutually_exclusive = [['name', 'aggregate']] module = AnsibleModule(argument_spec=argument_spec, required_one_of=required_one_of, mutually_exclusive=mutually_exclusive, supports_check_mode=True) warnings = list() check_args(module, warnings) result = {'changed': False} if warnings: result['warnings'] = warnings want = map_params_to_obj(module) for w in want: name = w['name'] name = name.lower() if is_switchport(name, module): module.fail_json( msg='Ensure interface is configured to be a L3' '\nport first before using this module. You can use' '\nthe cnos_interface module for this.') have = map_config_to_obj(module) commands = map_obj_to_commands((want, have), module) result['commands'] = commands if commands: if not module.check_mode: load_config(module, commands) result['changed'] = True check_declarative_intent_params(want, module, result) module.exit_json(**result)
def main(): """ main entry point for module execution """ element_spec = dict( vlan_id=dict(type='int'), name=dict(), interfaces=dict(type='list'), associated_interfaces=dict(type='list'), delay=dict(default=10, type='int'), state=dict(default='present', choices=['present', 'absent', 'active', 'suspend'])) aggregate_spec = deepcopy(element_spec) aggregate_spec['vlan_id'] = dict(required=True) # remove default in aggregate spec, to handle common arguments remove_default_spec(aggregate_spec) argument_spec = dict(aggregate=dict(type='list', elements='dict', options=aggregate_spec), purge=dict(default=False, type='bool')) argument_spec.update(element_spec) argument_spec.update(eos_argument_spec) required_one_of = [['vlan_id', 'aggregate']] mutually_exclusive = [['vlan_id', 'aggregate']] module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True, required_one_of=required_one_of, mutually_exclusive=mutually_exclusive) warnings = list() result = {'changed': False} if warnings: result['warnings'] = warnings want = map_params_to_obj(module) have = map_config_to_obj(module) commands = map_obj_to_commands((want, have), module) result['commands'] = commands if commands: commit = not module.check_mode response = load_config(module, commands, commit=commit) if response.get('diff') and module._diff: result['diff'] = {'prepared': response.get('diff')} result['session_name'] = response.get('session') result['changed'] = True check_declarative_intent_params(want, module, result) module.exit_json(**result)
def main(): """ main entry point for module execution """ element_spec = dict( prefix=dict(type="str"), mask=dict(type="str"), next_hop=dict(type="str"), vrf=dict(type="str"), interface=dict(type="str"), name=dict(type="str", aliases=["description"]), admin_distance=dict(type="str"), track=dict(type="str"), tag=dict(type="str"), state=dict(default="present", choices=["present", "absent"]), ) aggregate_spec = deepcopy(element_spec) aggregate_spec["prefix"] = dict(required=True) # remove default in aggregate spec, to handle common arguments remove_default_spec(aggregate_spec) argument_spec = dict( aggregate=dict(type="list", elements="dict", options=aggregate_spec)) argument_spec.update(element_spec) argument_spec.update(ios_argument_spec) required_one_of = [["aggregate", "prefix"]] required_together = [["prefix", "mask"]] mutually_exclusive = [["aggregate", "prefix"]] module = AnsibleModule( argument_spec=argument_spec, required_one_of=required_one_of, mutually_exclusive=mutually_exclusive, supports_check_mode=True, ) warnings = list() result = {"changed": False} if warnings: result["warnings"] = warnings want = map_params_to_obj(module, required_together=required_together) have = map_config_to_obj(module) commands = map_obj_to_commands(want, have) result["commands"] = commands if commands: if not module.check_mode: load_config(module, commands) result["changed"] = True module.exit_json(**result)
def main(): """ main entry point for module execution """ element_spec = dict( dest=dict( type="str", choices=["console", "file", "global", "host", "user"] ), name=dict(type="str"), facility=dict(type="str"), level=dict(type="str"), state=dict(default="present", choices=["present", "absent"]), ) aggregate_spec = deepcopy(element_spec) # remove default in aggregate spec, to handle common arguments remove_default_spec(aggregate_spec) argument_spec = dict( aggregate=dict(type="list", elements="dict", options=aggregate_spec), ) argument_spec.update(element_spec) argument_spec.update(vyos_argument_spec) required_if = [ ("dest", "host", ["name", "facility", "level"]), ("dest", "file", ["name", "facility", "level"]), ("dest", "user", ["name", "facility", "level"]), ("dest", "console", ["facility", "level"]), ("dest", "global", ["facility", "level"]), ] module = AnsibleModule( argument_spec=argument_spec, required_if=required_if, supports_check_mode=True, ) warnings = list() result = {"changed": False} if warnings: result["warnings"] = warnings want = map_params_to_obj(module, required_if=required_if) have = config_to_dict(module) commands = spec_to_commands((want, have), module) result["commands"] = commands if commands: commit = not module.check_mode load_config(module, commands, commit=commit) result["changed"] = True module.exit_json(**result)
def main(): """ main entry point for module execution """ element_spec = dict( name=dict(), ipv4=dict(), ipv6=dict(), replace=dict(choices=['yes', 'no']), mode=dict(choices=['dynamic', 'ospf-ignore', 'ospf-passive']), secondary=dict(choices=['yes', 'no']), check_running_config=dict( default=True, type='bool', fallback=(env_fallback, ['ANSIBLE_CHECK_ICX_RUNNING_CONFIG'])), state=dict(default='present', choices=['present', 'absent']), ) aggregate_spec = deepcopy(element_spec) aggregate_spec['name'] = dict(required=True) remove_default_spec(aggregate_spec) argument_spec = dict( aggregate=dict(type='list', elements='dict', options=aggregate_spec)) argument_spec.update(element_spec) required_one_of = [['name', 'aggregate']] mutually_exclusive = [['name', 'aggregate'], ['secondary', 'replace'], ['secondary', 'mode']] module = AnsibleModule(argument_spec=argument_spec, required_one_of=required_one_of, mutually_exclusive=mutually_exclusive, supports_check_mode=True) warnings = list() result = {'changed': False} exec_command(module, 'skip') want = map_params_to_obj(module) have = map_config_to_obj(module) commands = map_obj_to_commands((want, have), module) if commands: if not module.check_mode: resp = load_config(module, commands) warnings.extend((out for out in resp if out)) result['changed'] = True if warnings: result['warnings'] = warnings result['commands'] = commands module.exit_json(**result)
def main(): """entry point for module execution """ element_spec = dict(name=dict(), configured_password=dict(no_log=True), nopassword=dict(type='bool', default=False), update_password=dict(default='always', choices=['on_create', 'always']), privilege=dict(type='str', choices=['0', '4', '5']), access_time=dict(type='str'), state=dict(default='present', choices=['present', 'absent']), check_running_config=dict( default=True, type='bool', fallback=(env_fallback, ['ANSIBLE_CHECK_ICX_RUNNING_CONFIG']))) aggregate_spec = deepcopy(element_spec) aggregate_spec['name'] = dict(required=True) remove_default_spec(aggregate_spec) argument_spec = dict(aggregate=dict(type='list', elements='dict', options=aggregate_spec, aliases=['users', 'collection']), purge=dict(type='bool', default=False)) argument_spec.update(element_spec) mutually_exclusive = [('name', 'aggregate')] module = AnsibleModule(argument_spec=argument_spec, mutually_exclusive=mutually_exclusive, supports_check_mode=True) result = {'changed': False} exec_command(module, 'skip') want = map_params_to_obj(module) have = map_config_to_obj(module) commands = map_obj_to_commands(update_objects(want, have), module) if module.params['purge']: want_users = [x['name'] for x in want] have_users = [x['name'] for x in have] for item in set(have_users).difference(want_users): if item != 'admin': commands.append(user_del_cmd(item)) result["commands"] = commands if commands: if not module.check_mode: load_config(module, commands) result['changed'] = True module.exit_json(**result)
def __init__(self): self.lb_choice = [ 'dynamic-ratio-member', 'dynamic-ratio-node', 'fastest-app-response', 'fastest-node', 'least-connections-member', 'least-connections-node', 'least-sessions', 'observed-member', 'observed-node', 'predictive-member', 'predictive-node', 'ratio-least-connections-member', 'ratio-least-connections-node', 'ratio-member', 'ratio-node', 'ratio-session', 'round-robin', 'weighted-least-connections-member', 'weighted-least-connections-node' ] self.supports_check_mode = True element_spec = dict( name=dict(aliases=['pool']), lb_method=dict(choices=self.lb_choice), monitor_type=dict(choices=['and_list', 'm_of_n', 'single']), quorum=dict(type='int'), monitors=dict( type='list', elements='str', ), slow_ramp_time=dict(type='int'), reselect_tries=dict(type='int'), service_down_action=dict( choices=['none', 'reset', 'drop', 'reselect']), description=dict(), metadata=dict(type='raw'), state=dict(default='present', choices=['present', 'absent']), priority_group_activation=dict(type='int', aliases=['minimum_active_members']), partition=dict(default='Common', fallback=(env_fallback, ['F5_PARTITION']))) aggregate_spec = deepcopy(element_spec) # remove default in aggregate spec, to handle common arguments remove_default_spec(aggregate_spec) argument_spec = dict(aggregate=dict(type='list', elements='dict', options=aggregate_spec, aliases=['pools']), partition=dict(default='Common', fallback=(env_fallback, ['F5_PARTITION'])), replace_all_with=dict(default='no', type='bool', aliases=['purge'])) self.mutually_exclusive = [['name', 'aggregate']] self.required_one_of = [['name', 'aggregate']] self.argument_spec = {} self.argument_spec.update(element_spec) self.argument_spec.update(f5_argument_spec) self.argument_spec.update(argument_spec)
def main(): """ main entry point for module execution """ element_spec = dict( dest=dict( type="str", choices=["on", "host", "console", "monitor", "buffered", "trap"], ), name=dict(type="str"), size=dict(type="int"), facility=dict(type="str"), level=dict( type="str", default="debugging", choices=[ "emergencies", "alerts", "critical", "errors", "warnings", "notifications", "informational", "debugging", ], ), state=dict(default="present", choices=["present", "absent"]), ) aggregate_spec = deepcopy(element_spec) # remove default in aggregate spec, to handle common arguments remove_default_spec(aggregate_spec) argument_spec = dict( aggregate=dict(type="list", elements="dict", options=aggregate_spec) ) argument_spec.update(element_spec) argument_spec.update(ios_argument_spec) required_if = [("dest", "host", ["name"])] module = AnsibleModule( argument_spec=argument_spec, required_if=required_if, supports_check_mode=True, ) device_info = get_capabilities(module) os_version = device_info["device_info"]["network_os_version"] warnings = list() result = {"changed": False} if warnings: result["warnings"] = warnings want = map_params_to_obj(module, required_if=required_if) have = map_config_to_obj(module) commands = map_obj_to_commands((want, have), module, os_version) result["commands"] = commands if commands: if not module.check_mode: load_config(module, commands) result["changed"] = True module.exit_json(**result)
def main(): """ main entry point for module execution """ element_spec = dict(prefix=dict(type='str'), mask=dict(type='str'), next_hop=dict(type='str'), vrf=dict(type='str'), interface=dict(type='str'), name=dict(type='str', aliases=['description']), admin_distance=dict(type='str'), track=dict(type='str'), tag=dict(type='str'), state=dict(default='present', choices=['present', 'absent'])) aggregate_spec = deepcopy(element_spec) aggregate_spec['prefix'] = dict(required=True) # remove default in aggregate spec, to handle common arguments remove_default_spec(aggregate_spec) argument_spec = dict(aggregate=dict(type='list', elements='dict', options=aggregate_spec), ) argument_spec.update(element_spec) argument_spec.update(ios_argument_spec) required_one_of = [['aggregate', 'prefix']] required_together = [['prefix', 'mask']] mutually_exclusive = [['aggregate', 'prefix']] module = AnsibleModule(argument_spec=argument_spec, required_one_of=required_one_of, mutually_exclusive=mutually_exclusive, supports_check_mode=True) warnings = list() result = {'changed': False} if warnings: result['warnings'] = warnings want = map_params_to_obj(module, required_together=required_together) have = map_config_to_obj(module) commands = map_obj_to_commands(want, have) result['commands'] = commands if commands: if not module.check_mode: load_config(module, commands) result['changed'] = True module.exit_json(**result)
def build_aggregate_spec(element_spec, required, *extra_spec): aggregate_spec = deepcopy(element_spec) for elt in required: aggregate_spec[elt] = dict(required=True) remove_default_spec(aggregate_spec) argument_spec = dict( aggregate=dict(type='list', elements='dict', options=aggregate_spec)) argument_spec.update(element_spec) for elt in extra_spec: argument_spec.update(elt) return argument_spec
def main(): """ main entry point for module execution """ element_spec = dict(name=dict(), mode=dict(choices=[ '802.3ad', 'active-backup', 'broadcast', 'round-robin', 'transmit-load-balance', 'adaptive-load-balance', 'xor-hash', 'on' ], default='802.3ad'), members=dict(type='list'), state=dict(default='present', choices=['present', 'absent', 'up', 'down'])) aggregate_spec = deepcopy(element_spec) aggregate_spec['name'] = dict(required=True) # remove default in aggregate spec, to handle common arguments remove_default_spec(aggregate_spec) argument_spec = dict(aggregate=dict(type='list', elements='dict', options=aggregate_spec), ) argument_spec.update(element_spec) argument_spec.update(vyos_argument_spec) required_one_of = [['name', 'aggregate']] mutually_exclusive = [['name', 'aggregate']] module = AnsibleModule(argument_spec=argument_spec, required_one_of=required_one_of, mutually_exclusive=mutually_exclusive, supports_check_mode=True) warnings = list() result = {'changed': False} if warnings: result['warnings'] = warnings want = map_params_to_obj(module) have = map_config_to_obj(module) commands = map_obj_to_commands((want, have), module) result['commands'] = commands if commands: commit = not module.check_mode load_config(module, commands, commit=commit) result['changed'] = True module.exit_json(**result)
def main(): """main entry point for module execution""" neighbors_spec = dict(host=dict(), port=dict()) element_spec = dict( name=dict(), description=dict(), speed=dict(), mtu=dict(), duplex=dict(choices=["full", "half", "auto"]), enabled=dict(default=True, type="bool"), tx_rate=dict(), rx_rate=dict(), neighbors=dict(type="list", elements="dict", options=neighbors_spec), delay=dict(default=10, type="int"), state=dict( default="present", choices=["present", "absent", "up", "down"], ), ) aggregate_spec = deepcopy(element_spec) aggregate_spec["name"] = dict(required=True) # remove default in aggregate spec, to handle common arguments remove_default_spec(aggregate_spec) argument_spec = dict(aggregate=dict(type="list", elements="dict", options=aggregate_spec), ) argument_spec.update(element_spec) argument_spec.update(ios_argument_spec) required_one_of = [["name", "aggregate"]] mutually_exclusive = [["name", "aggregate"]] module = AnsibleModule( argument_spec=argument_spec, required_one_of=required_one_of, mutually_exclusive=mutually_exclusive, supports_check_mode=True, ) warnings = list() result = {"changed": False} if warnings: result["warnings"] = warnings want = map_params_to_obj(module) have = map_config_to_obj(module) commands = map_obj_to_commands((want, have)) result["commands"] = commands if commands: if not module.check_mode: load_config(module, commands) result["changed"] = True failed_conditions = check_declarative_intent_params(module, want, result) if failed_conditions: msg = "One or more conditional statements have not been satisfied" module.fail_json(msg=msg, failed_conditions=failed_conditions) module.exit_json(**result)
def main(): """ main entry point for module execution """ element_spec = dict( group=dict(type='int'), mode=dict(choices=['active', 'on', 'passive', 'auto', 'desirable']), members=dict(type='list'), state=dict(default='present', choices=['present', 'absent']) ) aggregate_spec = deepcopy(element_spec) aggregate_spec['group'] = dict(required=True) required_one_of = [['group', 'aggregate']] required_together = [['members', 'mode']] mutually_exclusive = [['group', 'aggregate']] # remove default in aggregate spec, to handle common arguments remove_default_spec(aggregate_spec) argument_spec = dict( aggregate=dict(type='list', elements='dict', options=aggregate_spec, required_together=required_together), purge=dict(default=False, type='bool') ) argument_spec.update(element_spec) argument_spec.update(ios_argument_spec) module = AnsibleModule(argument_spec=argument_spec, required_one_of=required_one_of, required_together=required_together, mutually_exclusive=mutually_exclusive, supports_check_mode=True) warnings = list() result = {'changed': False} if warnings: result['warnings'] = warnings want = map_params_to_obj(module) have = map_config_to_obj(module) commands = map_obj_to_commands((want, have), module) result['commands'] = commands if commands: if not module.check_mode: load_config(module, commands) result['changed'] = True module.exit_json(**result)
def main(): """ main entry point for module execution """ element_spec = dict( dest=dict(choices=DEST_GROUP), name=dict(), size=dict(type="int"), facility=dict(), level=dict(choices=LEVEL_GROUP), state=dict(default="present", choices=["present", "absent"]), ) aggregate_spec = deepcopy(element_spec) # remove default in aggregate spec, to handle common arguments remove_default_spec(aggregate_spec) aggregate_spec["state"].update(default="present") argument_spec = dict( aggregate=dict(type="list", elements="dict", options=aggregate_spec)) argument_spec.update(element_spec) argument_spec.update(eos_argument_spec) required_if = [("dest", "host", ["name"])] module = AnsibleModule( argument_spec=argument_spec, required_if=required_if, supports_check_mode=True, ) warnings = list() result = {"changed": False} if warnings: result["warnings"] = warnings have = map_config_to_obj(module) want = map_params_to_obj(module, required_if=required_if) commands = map_obj_to_commands((want, have), module) result["commands"] = commands if commands: commit = not module.check_mode response = load_config(module, commands, commit=commit) if response.get("diff") and module._diff: result["diff"] = {"prepared": response.get("diff")} result["session_name"] = response.get("session") result["changed"] = True module.exit_json(**result)
def main(): """ main entry point for module execution """ element_spec = dict( name=dict(), state=dict( default="present", choices=["present", "absent", "enabled", "disabled"], ), ) aggregate_spec = deepcopy(element_spec) aggregate_spec["name"] = dict(required=True) # remove default in aggregate spec, to handle common arguments remove_default_spec(aggregate_spec) argument_spec = dict(aggregate=dict(type="list", elements="dict", options=aggregate_spec), ) argument_spec.update(element_spec) argument_spec.update(vyos_argument_spec) required_one_of = [["name", "aggregate"]] mutually_exclusive = [["name", "aggregate"]] module = AnsibleModule( argument_spec=argument_spec, required_one_of=required_one_of, mutually_exclusive=mutually_exclusive, supports_check_mode=True, ) warnings = list() result = {"changed": False} if warnings: result["warnings"] = warnings want = map_params_to_obj(module) have = map_config_to_obj(module) commands = map_obj_to_commands((want, have), module) result["commands"] = commands if commands: commit = not module.check_mode load_config(module, commands, commit=commit) result["changed"] = True module.exit_json(**result)
def main(): """ main entry point for module execution """ element_spec = dict(name=dict(), full_name=dict(), level=dict(aliases=['role']), configured_password=dict(no_log=True), update_password=dict(default='always', choices=['on_create', 'always']), state=dict(default='present', choices=['present', 'absent'])) aggregate_spec = deepcopy(element_spec) aggregate_spec['name'] = dict(required=True) # remove default in aggregate spec, to handle common arguments remove_default_spec(aggregate_spec) argument_spec = dict(aggregate=dict(type='list', elements='dict', options=aggregate_spec, aliases=['users', 'collection']), purge=dict(type='bool', default=False)) argument_spec.update(element_spec) argument_spec.update(vyos_argument_spec) mutually_exclusive = [('name', 'aggregate')] module = AnsibleModule(argument_spec=argument_spec, mutually_exclusive=mutually_exclusive, supports_check_mode=True) warnings = list() result = {'changed': False, 'warnings': warnings} want = map_params_to_obj(module) have = config_to_dict(module) commands = spec_to_commands(update_objects(want, have), module) if module.params['purge']: want_users = [x['name'] for x in want] have_users = [x['name'] for x in have] for item in set(have_users).difference(want_users): commands.append('delete system login user %s' % item) result['commands'] = commands if commands: commit = not module.check_mode load_config(module, commands, commit=commit) result['changed'] = True module.exit_json(**result)