def main(): argument_spec = aci_argument_spec() argument_spec.update( allow_useg=dict(type='str', choices=['encap', 'useg']), ap=dict(type='str', aliases=['app_profile', 'app_profile_name']), # Not required for querying all objects deploy_immediacy=dict(type='str', choices=['immediate', 'lazy']), domain=dict(type='str', aliases=['domain_name', 'domain_profile']), # Not required for querying all objects domain_type=dict(type='str', choices=['l2dom', 'phys', 'vmm'], aliases=['type']), # Not required for querying all objects encap=dict(type='int'), encap_mode=dict(type='str', choices=['auto', 'vlan', 'vxlan']), switching_mode=dict(type='str', default='native', choices=['AVE', 'native']), epg=dict(type='str', aliases=['name', 'epg_name']), # Not required for querying all objects netflow=dict(type='bool'), primary_encap=dict(type='int'), resolution_immediacy=dict(type='str', choices=['immediate', 'lazy', 'pre-provision']), state=dict(type='str', default='present', choices=['absent', 'present', 'query']), tenant=dict(type='str', aliases=['tenant_name']), # Not required for querying all objects vm_provider=dict(type='str', choices=['cloudfoundry', 'kubernetes', 'microsoft', 'openshift', 'openstack', 'redhat', 'vmware']), ) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True, required_if=[ ['domain_type', 'vmm', ['vm_provider']], ['state', 'absent', ['ap', 'domain', 'domain_type', 'epg', 'tenant']], ['state', 'present', ['ap', 'domain', 'domain_type', 'epg', 'tenant']], ], ) aci = ACIModule(module) allow_useg = module.params.get('allow_useg') ap = module.params.get('ap') deploy_immediacy = module.params.get('deploy_immediacy') domain = module.params.get('domain') domain_type = module.params.get('domain_type') vm_provider = module.params.get('vm_provider') encap = module.params.get('encap') if encap is not None: if encap in range(1, 4097): encap = 'vlan-{0}'.format(encap) else: module.fail_json(msg='Valid VLAN assignments are from 1 to 4096') encap_mode = module.params.get('encap_mode') switching_mode = module.params.get('switching_mode') epg = module.params.get('epg') netflow = aci.boolean(module.params.get('netflow'), 'enabled', 'disabled') primary_encap = module.params.get('primary_encap') if primary_encap is not None: if primary_encap in range(1, 4097): primary_encap = 'vlan-{0}'.format(primary_encap) else: module.fail_json(msg='Valid VLAN assignments are from 1 to 4096') resolution_immediacy = module.params.get('resolution_immediacy') state = module.params.get('state') tenant = module.params.get('tenant') if domain_type in ['l2dom', 'phys'] and vm_provider is not None: module.fail_json(msg="Domain type '%s' cannot have a 'vm_provider'" % domain_type) # Compile the full domain for URL building if domain_type == 'vmm': epg_domain = 'uni/vmmp-{0}/dom-{1}'.format(VM_PROVIDER_MAPPING[vm_provider], domain) elif domain_type == 'l2dom': epg_domain = 'uni/l2dom-{0}'.format(domain) elif domain_type == 'phys': epg_domain = 'uni/phys-{0}'.format(domain) else: epg_domain = None aci.construct_url( root_class=dict( aci_class='fvTenant', aci_rn='tn-{0}'.format(tenant), module_object=tenant, target_filter={'name': tenant}, ), subclass_1=dict( aci_class='fvAp', aci_rn='ap-{0}'.format(ap), module_object=ap, target_filter={'name': ap}, ), subclass_2=dict( aci_class='fvAEPg', aci_rn='epg-{0}'.format(epg), module_object=epg, target_filter={'name': epg}, ), subclass_3=dict( aci_class='fvRsDomAtt', aci_rn='rsdomAtt-[{0}]'.format(epg_domain), module_object=epg_domain, target_filter={'tDn': epg_domain}, ), ) aci.get_existing() if state == 'present': aci.payload( aci_class='fvRsDomAtt', class_config=dict( classPref=allow_useg, encap=encap, encapMode=encap_mode, switchingMode=switching_mode, instrImedcy=deploy_immediacy, netflowPref=netflow, primaryEncap=primary_encap, resImedcy=resolution_immediacy, ), ) aci.get_diff(aci_class='fvRsDomAtt') aci.post_config() elif state == 'absent': aci.delete_config() aci.exit_json()
def main(): argument_spec = aci_argument_spec() argument_spec.update( contract=dict(type='str', aliases=['contract_name' ]), # Not required for querying all objects subject=dict(type='str', aliases=['contract_subject', 'name', 'subject_name' ]), # Not required for querying all objects tenant=dict(type='str', aliases=['tenant_name' ]), # Not required for querying all objects priority=dict(type='str', choices=['unspecified', 'level1', 'level2', 'level3']), reverse_filter=dict(type='bool'), dscp=dict(type='str', aliases=['target'], choices=[ 'AF11', 'AF12', 'AF13', 'AF21', 'AF22', 'AF23', 'AF31', 'AF32', 'AF33', 'AF41', 'AF42', 'AF43', 'CS0', 'CS1', 'CS2', 'CS3', 'CS4', 'CS5', 'CS6', 'CS7', 'EF', 'VA', 'unspecified' ]), description=dict(type='str', aliases=['descr']), consumer_match=dict( type='str', choices=['all', 'at_least_one', 'at_most_one', 'none']), provider_match=dict( type='str', choices=['all', 'at_least_one', 'at_most_one', 'none']), state=dict(type='str', default='present', choices=['absent', 'present', 'query']), name_alias=dict(type='str'), ) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True, required_if=[ ['state', 'absent', ['contract', 'subject', 'tenant']], ['state', 'present', ['contract', 'subject', 'tenant']], ], ) aci = ACIModule(module) subject = module.params.get('subject') priority = module.params.get('priority') reverse_filter = aci.boolean(module.params.get('reverse_filter')) contract = module.params.get('contract') dscp = module.params.get('dscp') description = module.params.get('description') consumer_match = module.params.get('consumer_match') if consumer_match is not None: consumer_match = MATCH_MAPPING.get(consumer_match) provider_match = module.params.get('provider_match') if provider_match is not None: provider_match = MATCH_MAPPING.get(provider_match) state = module.params.get('state') tenant = module.params.get('tenant') name_alias = module.params.get('name_alias') aci.construct_url( root_class=dict( aci_class='fvTenant', aci_rn='tn-{0}'.format(tenant), module_object=tenant, target_filter={'name': tenant}, ), subclass_1=dict( aci_class='vzBrCP', aci_rn='brc-{0}'.format(contract), module_object=contract, target_filter={'name': contract}, ), subclass_2=dict( aci_class='vzSubj', aci_rn='subj-{0}'.format(subject), module_object=subject, target_filter={'name': subject}, ), ) aci.get_existing() if state == 'present': aci.payload( aci_class='vzSubj', class_config=dict( name=subject, prio=priority, revFltPorts=reverse_filter, targetDscp=dscp, consMatchT=consumer_match, provMatchT=provider_match, descr=description, nameAlias=name_alias, ), ) aci.get_diff(aci_class='vzSubj') aci.post_config() elif state == 'absent': aci.delete_config() aci.exit_json()
def main(): argument_spec = aci_argument_spec() argument_spec.update( epg=dict(type='str', aliases=['epg_name', 'name']), # Not required for querying all objects bd=dict(type='str', aliases=['bd_name', 'bridge_domain']), ap=dict(type='str', aliases=['app_profile', 'app_profile_name' ]), # Not required for querying all objects tenant=dict(type='str', aliases=['tenant_name' ]), # Not required for querying all objects description=dict(type='str', aliases=['descr']), priority=dict(type='str', choices=['level1', 'level2', 'level3', 'unspecified']), intra_epg_isolation=dict(choices=['enforced', 'unenforced']), fwd_control=dict(type='str', choices=['none', 'proxy-arp']), preferred_group=dict(type='bool'), state=dict(type='str', default='present', choices=['absent', 'present', 'query']), name_alias=dict(type='str'), ) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True, required_if=[ ['state', 'absent', ['ap', 'epg', 'tenant']], ['state', 'present', ['ap', 'epg', 'tenant']], ], ) aci = ACIModule(module) epg = module.params.get('epg') bd = module.params.get('bd') description = module.params.get('description') priority = module.params.get('priority') intra_epg_isolation = module.params.get('intra_epg_isolation') fwd_control = module.params.get('fwd_control') preferred_group = aci.boolean(module.params.get('preferred_group'), 'include', 'exclude') state = module.params.get('state') tenant = module.params.get('tenant') ap = module.params.get('ap') name_alias = module.params.get('name_alias') aci.construct_url( root_class=dict( aci_class='fvTenant', aci_rn='tn-{0}'.format(tenant), module_object=tenant, target_filter={'name': tenant}, ), subclass_1=dict( aci_class='fvAp', aci_rn='ap-{0}'.format(ap), module_object=ap, target_filter={'name': ap}, ), subclass_2=dict( aci_class='fvAEPg', aci_rn='epg-{0}'.format(epg), module_object=epg, target_filter={'name': epg}, ), child_classes=['fvRsBd'], ) aci.get_existing() if state == 'present': aci.payload( aci_class='fvAEPg', class_config=dict( name=epg, descr=description, prio=priority, pcEnfPref=intra_epg_isolation, fwdCtrl=fwd_control, prefGrMemb=preferred_group, nameAlias=name_alias, ), child_configs=[ dict(fvRsBd=dict(attributes=dict(tnFvBDName=bd, ), ), ) ], ) aci.get_diff(aci_class='fvAEPg') aci.post_config() elif state == 'absent': aci.delete_config() aci.exit_json()
def main(): argument_spec = aci_argument_spec() argument_spec.update( bd=dict(type='str', aliases=['bd_name']), # Not required for querying all objects description=dict(type='str', aliases=['descr']), enable_vip=dict(type='bool'), gateway=dict(type='str', aliases=['gateway_ip']), # Not required for querying all objects mask=dict(type='int', aliases=['subnet_mask']), # Not required for querying all objects subnet_name=dict(type='str', aliases=['name']), nd_prefix_policy=dict(type='str'), preferred=dict(type='bool'), route_profile=dict(type='str'), route_profile_l3_out=dict(type='str'), scope=dict(type='list', choices=['private', 'public', 'shared']), subnet_control=dict(type='str', choices=['nd_ra', 'no_gw', 'querier_ip', 'unspecified']), state=dict(type='str', default='present', choices=['absent', 'present', 'query']), tenant=dict(type='str', aliases=['tenant_name']), # Not required for querying all objects name_alias=dict(type='str'), ) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True, required_together=[['gateway', 'mask']], required_if=[ ['state', 'present', ['bd', 'gateway', 'mask', 'tenant']], ['state', 'absent', ['bd', 'gateway', 'mask', 'tenant']], ], ) aci = ACIModule(module) description = module.params.get('description') enable_vip = aci.boolean(module.params.get('enable_vip')) tenant = module.params.get('tenant') bd = module.params.get('bd') gateway = module.params.get('gateway') mask = module.params.get('mask') if mask is not None and mask not in range(0, 129): # TODO: split checks between IPv4 and IPv6 Addresses module.fail_json(msg='Valid Subnet Masks are 0 to 32 for IPv4 Addresses and 0 to 128 for IPv6 addresses') if gateway is not None: gateway = '{0}/{1}'.format(gateway, str(mask)) subnet_name = module.params.get('subnet_name') nd_prefix_policy = module.params.get('nd_prefix_policy') preferred = aci.boolean(module.params.get('preferred')) route_profile = module.params.get('route_profile') route_profile_l3_out = module.params.get('route_profile_l3_out') scope = module.params.get('scope') if scope is not None: if 'private' in scope and 'public' in scope: module.fail_json(msg="Parameter 'scope' cannot be both 'private' and 'public', got: %s" % scope) else: scope = ','.join(sorted(scope)) state = module.params.get('state') subnet_control = module.params.get('subnet_control') if subnet_control: subnet_control = SUBNET_CONTROL_MAPPING[subnet_control] name_alias = module.params.get('name_alias') aci.construct_url( root_class=dict( aci_class='fvTenant', aci_rn='tn-{0}'.format(tenant), module_object=tenant, target_filter={'name': tenant}, ), subclass_1=dict( aci_class='fvBD', aci_rn='BD-{0}'.format(bd), module_object=bd, target_filter={'name': bd}, ), subclass_2=dict( aci_class='fvSubnet', aci_rn='subnet-[{0}]'.format(gateway), module_object=gateway, target_filter={'ip': gateway}, ), child_classes=['fvRsBDSubnetToProfile', 'fvRsNdPfxPol'], ) aci.get_existing() if state == 'present': aci.payload( aci_class='fvSubnet', class_config=dict( ctrl=subnet_control, descr=description, ip=gateway, name=subnet_name, preferred=preferred, scope=scope, virtual=enable_vip, nameAlias=name_alias, ), child_configs=[ {'fvRsBDSubnetToProfile': {'attributes': {'tnL3extOutName': route_profile_l3_out, 'tnRtctrlProfileName': route_profile}}}, {'fvRsNdPfxPol': {'attributes': {'tnNdPfxPolName': nd_prefix_policy}}}, ], ) aci.get_diff(aci_class='fvSubnet') aci.post_config() elif state == 'absent': aci.delete_config() aci.exit_json()
def main(): argument_spec = aci_argument_spec() argument_spec.update( contract=dict(type='str', aliases=['contract_name', 'name' ]), # Not required for querying all objects tenant=dict(type='str', aliases=['tenant_name' ]), # Not required for querying all objects description=dict(type='str', aliases=['descr']), scope=dict( type='str', choices=['application-profile', 'context', 'global', 'tenant']), priority=dict(type='str', choices=['level1', 'level2', 'level3', 'unspecified' ]), # No default provided on purpose dscp=dict(type='str', choices=[ 'AF11', 'AF12', 'AF13', 'AF21', 'AF22', 'AF23', 'AF31', 'AF32', 'AF33', 'AF41', 'AF42', 'AF43', 'CS0', 'CS1', 'CS2', 'CS3', 'CS4', 'CS5', 'CS6', 'CS7', 'EF', 'VA', 'unspecified' ], aliases=['target']), # No default provided on purpose state=dict(type='str', default='present', choices=['absent', 'present', 'query']), name_alias=dict(type='str'), ) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True, required_if=[ ['state', 'absent', ['contract', 'tenant']], ['state', 'present', ['contract', 'tenant']], ], ) contract = module.params.get('contract') description = module.params.get('description') scope = module.params.get('scope') priority = module.params.get('priority') dscp = module.params.get('dscp') state = module.params.get('state') tenant = module.params.get('tenant') name_alias = module.params.get('name_alias') aci = ACIModule(module) aci.construct_url( root_class=dict( aci_class='fvTenant', aci_rn='tn-{0}'.format(tenant), module_object=tenant, target_filter={'name': tenant}, ), subclass_1=dict( aci_class='vzBrCP', aci_rn='brc-{0}'.format(contract), module_object=contract, target_filter={'name': contract}, ), ) aci.get_existing() if state == 'present': aci.payload( aci_class='vzBrCP', class_config=dict( name=contract, descr=description, scope=scope, prio=priority, targetDscp=dscp, nameAlias=name_alias, ), ) aci.get_diff(aci_class='vzBrCP') aci.post_config() elif state == 'absent': aci.delete_config() aci.exit_json()
def main(): argument_spec = aci_argument_spec() argument_spec.update( domain_type=dict(type='str', required=True, choices=['fc', 'l2dom', 'l3dom', 'phys', 'vmm']), pool_type=dict(type='str', required=True, choices=['vlan', 'vsan', 'vxlan']), domain=dict(type='str', aliases=['domain_name', 'domain_profile' ]), # Not required for querying all objects pool=dict(type='str', aliases=['pool_name' ]), # Not required for querying all objects pool_allocation_mode=dict(type='str', aliases=['allocation_mode', 'mode'], choices=['dynamic', 'static']), state=dict(type='str', default='present', choices=['absent', 'present', 'query']), vm_provider=dict(type='str', choices=[ 'cloudfoundry', 'kubernetes', 'microsoft', 'openshift', 'openstack', 'redhat', 'vmware' ]), ) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True, required_if=[ ['domain_type', 'vmm', ['vm_provider']], [ 'state', 'absent', ['domain', 'domain_type', 'pool', 'pool_type'] ], [ 'state', 'present', ['domain', 'domain_type', 'pool', 'pool_type'] ], ], ) domain = module.params.get('domain') domain_type = module.params.get('domain_type') pool = module.params.get('pool') pool_allocation_mode = module.params.get('pool_allocation_mode') pool_type = module.params.get('pool_type') vm_provider = module.params.get('vm_provider') state = module.params.get('state') # Report when vm_provider is set when type is not virtual if domain_type != 'vmm' and vm_provider is not None: module.fail_json(msg="Domain type '{0}' cannot have a 'vm_provider'". format(domain_type)) # ACI Pool URL requires the allocation mode for vlan and vsan pools (ex: uni/infra/vlanns-[poolname]-static) pool_name = pool if pool_type != 'vxlan' and pool is not None: if pool_allocation_mode is not None: pool_name = '[{0}]-{1}'.format(pool, pool_allocation_mode) else: module.fail_json( msg= "ACI requires the 'pool_allocation_mode' for 'pool_type' of 'vlan' and 'vsan' when 'pool' is provided" ) # Vxlan pools do not support allocation modes if pool_type == 'vxlan' and pool_allocation_mode is not None: module.fail_json( msg= 'vxlan pools do not support setting the allocation_mode; please remove this parameter from the task' ) # Compile the full domain for URL building if domain_type == 'fc': domain_class = 'fcDomP' domain_mo = 'uni/fc-{0}'.format(domain) domain_rn = 'fc-{0}'.format(domain) elif domain_type == 'l2ext': domain_class = 'l2extDomP' domain_mo = 'uni/l2dom-{0}'.format(domain) domain_rn = 'l2dom-{0}'.format(domain) elif domain_type == 'l3ext': domain_class = 'l3extDomP' domain_mo = 'uni/l3dom-{0}'.format(domain) domain_rn = 'l3dom-{0}'.format(domain) elif domain_type == 'phys': domain_class = 'physDomP' domain_mo = 'uni/phys-{0}'.format(domain) domain_rn = 'phys-{0}'.format(domain) elif domain_type == 'vmm': domain_class = 'vmmDomP' domain_mo = 'uni/vmmp-{0}/dom-{1}'.format( VM_PROVIDER_MAPPING[vm_provider], domain) domain_rn = 'vmmp-{0}/dom-{1}'.format(VM_PROVIDER_MAPPING[vm_provider], domain) # Ensure that querying all objects works when only domain_type is provided if domain is None: domain_mo = None pool_mo = POOL_MAPPING[pool_type]['aci_mo'].format(pool_name) child_class = POOL_MAPPING[pool_type]['child_class'] aci = ACIModule(module) aci.construct_url( root_class=dict( aci_class=domain_class, aci_rn=domain_rn, module_object=domain_mo, target_filter={'name': domain}, ), child_classes=[child_class], ) aci.get_existing() if state == 'present': # Filter out module params with null values aci.payload(aci_class=domain_class, class_config=dict(name=domain), child_configs=[ { child_class: { 'attributes': { 'tDn': pool_mo } } }, ]) # Generate config diff which will be used as POST request body aci.get_diff(aci_class=domain_class) # Submit changes if module not in check_mode and the proposed is different than existing aci.post_config() elif state == 'absent': aci.delete_config() aci.exit_json()
def main(): argument_spec = aci_argument_spec() argument_spec.update( port_channel=dict(type='str', aliases=['name']), # Not required for querying all objects description=dict(type='str', aliases=['descr']), min_links=dict(type='int'), max_links=dict(type='int'), mode=dict(type='str', choices=['active', 'mac-pin', 'mac-pin-nicload', 'off', 'passive']), fast_select=dict(type='bool'), graceful_convergence=dict(type='bool'), load_defer=dict(type='bool'), suspend_individual=dict(type='bool'), symmetric_hash=dict(type='bool'), state=dict(type='str', default='present', choices=['absent', 'present', 'query']), ) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True, required_if=[ ['state', 'absent', ['port_channel']], ['state', 'present', ['port_channel']], ], ) port_channel = module.params.get('port_channel') description = module.params.get('description') min_links = module.params.get('min_links') if min_links is not None and min_links not in range(1, 17): module.fail_json(msg='The "min_links" must be a value between 1 and 16') max_links = module.params.get('max_links') if max_links is not None and max_links not in range(1, 17): module.fail_json(msg='The "max_links" must be a value between 1 and 16') mode = module.params.get('mode') state = module.params.get('state') # Build ctrl value for request ctrl = [] if module.params.get('fast_select') is True: ctrl.append('fast-sel-hot-stdby') if module.params.get('graceful_convergence') is True: ctrl.append('graceful-conv') if module.params.get('load_defer') is True: ctrl.append('load-defer') if module.params.get('suspend_individual') is True: ctrl.append('susp-individual') if module.params.get('symmetric_hash') is True: ctrl.append('symmetric-hash') if not ctrl: ctrl = None else: ctrl = ",".join(ctrl) aci = ACIModule(module) aci.construct_url( root_class=dict( aci_class='lacpLagPol', aci_rn='infra/lacplagp-{0}'.format(port_channel), module_object=port_channel, target_filter={'name': port_channel}, ), ) aci.get_existing() if state == 'present': aci.payload( aci_class='lacpLagPol', class_config=dict( name=port_channel, ctrl=ctrl, descr=description, minLinks=min_links, maxLinks=max_links, mode=mode, ), ) aci.get_diff(aci_class='lacpLagPol') aci.post_config() elif state == 'absent': aci.delete_config() aci.exit_json()
def main(): argument_spec = aci_argument_spec() argument_spec.update( arp_flooding=dict(type='bool'), bd=dict(type='str', aliases=['bd_name', 'name']), # Not required for querying all objects bd_type=dict(type='str', choices=['ethernet', 'fc']), description=dict(type='str'), enable_multicast=dict(type='bool'), enable_routing=dict(type='bool'), endpoint_clear=dict(type='bool'), endpoint_move_detect=dict(type='str', choices=['default', 'garp']), endpoint_retention_action=dict(type='str', choices=['inherit', 'resolve']), endpoint_retention_policy=dict(type='str'), igmp_snoop_policy=dict(type='str'), ip_learning=dict(type='bool'), ipv6_nd_policy=dict(type='str'), l2_unknown_unicast=dict(type='str', choices=['proxy', 'flood']), l3_unknown_multicast=dict(type='str', choices=['flood', 'opt-flood']), limit_ip_learn=dict(type='bool'), mac_address=dict(type='str', aliases=['mac']), multi_dest=dict(type='str', choices=['bd-flood', 'drop', 'encap-flood']), state=dict(type='str', default='present', choices=['absent', 'present', 'query']), tenant=dict(type='str', aliases=['tenant_name']), # Not required for querying all objects vrf=dict(type='str', aliases=['vrf_name']), name_alias=dict(type='str'), ) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True, required_if=[ ['state', 'absent', ['bd', 'tenant']], ['state', 'present', ['bd', 'tenant']], ], ) aci = ACIModule(module) arp_flooding = aci.boolean(module.params.get('arp_flooding')) bd = module.params.get('bd') bd_type = module.params.get('bd_type') if bd_type == 'ethernet': # ethernet type is represented as regular, but that is not clear to the users bd_type = 'regular' description = module.params.get('description') enable_multicast = aci.boolean(module.params.get('enable_multicast')) enable_routing = aci.boolean(module.params.get('enable_routing')) endpoint_clear = aci.boolean(module.params.get('endpoint_clear')) endpoint_move_detect = module.params.get('endpoint_move_detect') if endpoint_move_detect == 'default': # the ACI default setting is an empty string, but that is not a good input value endpoint_move_detect = '' endpoint_retention_action = module.params.get('endpoint_retention_action') endpoint_retention_policy = module.params.get('endpoint_retention_policy') igmp_snoop_policy = module.params.get('igmp_snoop_policy') ip_learning = aci.boolean(module.params.get('ip_learning')) ipv6_nd_policy = module.params.get('ipv6_nd_policy') l2_unknown_unicast = module.params.get('l2_unknown_unicast') l3_unknown_multicast = module.params.get('l3_unknown_multicast') limit_ip_learn = aci.boolean(module.params.get('limit_ip_learn')) mac_address = module.params.get('mac_address') multi_dest = module.params.get('multi_dest') state = module.params.get('state') tenant = module.params.get('tenant') vrf = module.params.get('vrf') name_alias = module.params.get('name_alias') aci.construct_url( root_class=dict( aci_class='fvTenant', aci_rn='tn-{0}'.format(tenant), module_object=tenant, target_filter={'name': tenant}, ), subclass_1=dict( aci_class='fvBD', aci_rn='BD-{0}'.format(bd), module_object=bd, target_filter={'name': bd}, ), child_classes=['fvRsCtx', 'fvRsIgmpsn', 'fvRsBDToNdP', 'fvRsBdToEpRet'], ) aci.get_existing() if state == 'present': aci.payload( aci_class='fvBD', class_config=dict( arpFlood=arp_flooding, descr=description, epClear=endpoint_clear, epMoveDetectMode=endpoint_move_detect, ipLearning=ip_learning, limitIpLearnToSubnets=limit_ip_learn, mac=mac_address, mcastAllow=enable_multicast, multiDstPktAct=multi_dest, name=bd, type=bd_type, unicastRoute=enable_routing, unkMacUcastAct=l2_unknown_unicast, unkMcastAct=l3_unknown_multicast, nameAlias=name_alias, ), child_configs=[ {'fvRsCtx': {'attributes': {'tnFvCtxName': vrf}}}, {'fvRsIgmpsn': {'attributes': {'tnIgmpSnoopPolName': igmp_snoop_policy}}}, {'fvRsBDToNdP': {'attributes': {'tnNdIfPolName': ipv6_nd_policy}}}, {'fvRsBdToEpRet': {'attributes': {'resolveAct': endpoint_retention_action, 'tnFvEpRetPolName': endpoint_retention_policy}}}, ], ) aci.get_diff(aci_class='fvBD') aci.post_config() elif state == 'absent': aci.delete_config() aci.exit_json()
def main(): argument_spec = aci_argument_spec() argument_spec.update( l2_policy=dict(type='str', aliases=['name' ]), # Not required for querying all policies description=dict(type='str', aliases=['descr']), vlan_scope=dict(type='str', choices=['global', 'portlocal' ]), # No default provided on purpose qinq=dict(type='str', choices=['core', 'disabled', 'edge']), vepa=dict(type='bool'), state=dict(type='str', default='present', choices=['absent', 'present', 'query']), ) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True, required_if=[ ['state', 'absent', ['l2_policy']], ['state', 'present', ['l2_policy']], ], ) aci = ACIModule(module) l2_policy = module.params.get('l2_policy') vlan_scope = module.params.get('vlan_scope') qinq = module.params.get('qinq') if qinq is not None: qinq = QINQ_MAPPING.get(qinq) vepa = aci.boolean(module.params.get('vepa'), 'enabled', 'disabled') description = module.params.get('description') state = module.params.get('state') aci.construct_url(root_class=dict( aci_class='l2IfPol', aci_rn='infra/l2IfP-{0}'.format(l2_policy), module_object=l2_policy, target_filter={'name': l2_policy}, ), ) aci.get_existing() if state == 'present': aci.payload( aci_class='l2IfPol', class_config=dict( name=l2_policy, descr=description, vlanScope=vlan_scope, qinq=qinq, vepa=vepa, ), ) aci.get_diff(aci_class='l2IfPol') aci.post_config() elif state == 'absent': aci.delete_config() aci.exit_json()
def main(): argument_spec = aci_argument_spec() argument_spec.update( action_rule=dict(type='str', aliases=['action_rule_name', 'name' ]), # Not required for querying all objects tenant=dict(type='str', aliases=['tenant_name' ]), # Not required for querying all objects description=dict(type='str', aliases=['descr']), state=dict(type='str', default='present', choices=['absent', 'present', 'query']), name_alias=dict(type='str'), ) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True, required_if=[ ['state', 'absent', ['action_rule', 'tenant']], ['state', 'present', ['action_rule', 'tenant']], ], ) action_rule = module.params.get('action_rule') description = module.params.get('description') state = module.params.get('state') tenant = module.params.get('tenant') name_alias = module.params.get('name_alias') aci = ACIModule(module) aci.construct_url( root_class=dict( aci_class='fvTenant', aci_rn='tn-{0}'.format(tenant), module_object=tenant, target_filter={'name': tenant}, ), subclass_1=dict( aci_class='rtctrlAttrP', aci_rn='attr-{0}'.format(action_rule), module_object=action_rule, target_filter={'name': action_rule}, ), ) aci.get_existing() if state == 'present': aci.payload( aci_class='rtctrlAttrP', class_config=dict( name=action_rule, descr=description, nameAlias=name_alias, ), ) aci.get_diff(aci_class='rtctrlAttrP') aci.post_config() elif state == 'absent': aci.delete_config() aci.exit_json()
def main(): argument_spec = aci_argument_spec() argument_spec.update( aaa_user=dict(type='str', required=True), aaa_user_type=dict(type='str', default='user', choices=['appuser', 'user']), certificate=dict(type='str', aliases=['cert_data', 'certificate_data']), certificate_name=dict( type='str', aliases=['cert_name']), # Not required for querying all objects state=dict(type='str', default='present', choices=['absent', 'present', 'query']), name_alias=dict(type='str'), ) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True, required_if=[ ['state', 'absent', ['aaa_user', 'certificate_name']], [ 'state', 'present', ['aaa_user', 'certificate', 'certificate_name'] ], ], ) aaa_user = module.params.get('aaa_user') aaa_user_type = module.params.get('aaa_user_type') certificate = module.params.get('certificate') certificate_name = module.params.get('certificate_name') state = module.params.get('state') name_alias = module.params.get('name_alias') aci = ACIModule(module) aci.construct_url( root_class=dict( aci_class=ACI_MAPPING.get(aaa_user_type).get('aci_class'), aci_rn=ACI_MAPPING.get(aaa_user_type).get('aci_mo') + aaa_user, module_object=aaa_user, target_filter={'name': aaa_user}, ), subclass_1=dict( aci_class='aaaUserCert', aci_rn='usercert-{0}'.format(certificate_name), module_object=certificate_name, target_filter={'name': certificate_name}, ), ) aci.get_existing() if state == 'present': aci.payload( aci_class='aaaUserCert', class_config=dict( data=certificate, name=certificate_name, nameAlias=name_alias, ), ) aci.get_diff(aci_class='aaaUserCert') aci.post_config() elif state == 'absent': aci.delete_config() aci.exit_json()
def main(): argument_spec = aci_argument_spec() argument_spec.update( aep=dict(type='str', aliases=['name', 'aep_name' ]), # Not required for querying all objects description=dict(type='str', aliases=['descr']), infra_vlan=dict(type='bool', aliases=['infrastructure_vlan']), state=dict(type='str', default='present', choices=['absent', 'present', 'query']), name_alias=dict(type='str'), ) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True, required_if=[ ['state', 'absent', ['aep']], ['state', 'present', ['aep']], ], ) aep = module.params.get('aep') description = module.params.get('description') infra_vlan = module.params.get('infra_vlan') state = module.params.get('state') name_alias = module.params.get('name_alias') if infra_vlan: child_configs = [ dict(infraProvAcc=dict(attributes=dict(name='provacc'))) ] elif infra_vlan is False: child_configs = [ dict(infraProvAcc=dict( attributes=dict(name='provacc', status='deleted'))) ] else: child_configs = [] aci = ACIModule(module) aci.construct_url(root_class=dict( aci_class='infraAttEntityP', aci_rn='infra/attentp-{0}'.format(aep), module_object=aep, target_filter={'name': aep}, ), ) aci.get_existing() if state == 'present': aci.payload( aci_class='infraAttEntityP', class_config=dict( name=aep, descr=description, nameAlias=name_alias, ), child_configs=child_configs, ) aci.get_diff(aci_class='infraAttEntityP') aci.post_config() elif state == 'absent': aci.delete_config() aci.exit_json()
def main(): argument_spec = aci_argument_spec() argument_spec.update( arp_flag=dict(type='str', choices=VALID_ARP_FLAGS), description=dict(type='str', aliases=['descr']), dst_port=dict(type='str'), dst_port_end=dict(type='str'), dst_port_start=dict(type='str'), entry=dict(type='str', aliases=['entry_name', 'filter_entry', 'name']), # Not required for querying all objects ether_type=dict(choices=VALID_ETHER_TYPES, type='str'), filter=dict(type='str', aliases=['filter_name' ]), # Not required for querying all objects icmp_msg_type=dict(type='str', choices=VALID_ICMP_TYPES), icmp6_msg_type=dict(type='str', choices=VALID_ICMP6_TYPES), ip_protocol=dict(choices=VALID_IP_PROTOCOLS, type='str'), state=dict(type='str', default='present', choices=['absent', 'present', 'query']), stateful=dict(type='bool'), tenant=dict(type='str', aliases=['tenant_name' ]), # Not required for querying all objects name_alias=dict(type='str'), ) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True, required_if=[ ['state', 'absent', ['entry', 'filter', 'tenant']], ['state', 'present', ['entry', 'filter', 'tenant']], ], ) aci = ACIModule(module) arp_flag = module.params.get('arp_flag') if arp_flag is not None: arp_flag = ARP_FLAG_MAPPING.get(arp_flag) description = module.params.get('description') dst_port = module.params.get('dst_port') if FILTER_PORT_MAPPING.get(dst_port) is not None: dst_port = FILTER_PORT_MAPPING.get(dst_port) dst_end = module.params.get('dst_port_end') if FILTER_PORT_MAPPING.get(dst_end) is not None: dst_end = FILTER_PORT_MAPPING.get(dst_end) dst_start = module.params.get('dst_port_start') if FILTER_PORT_MAPPING.get(dst_start) is not None: dst_start = FILTER_PORT_MAPPING.get(dst_start) entry = module.params.get('entry') ether_type = module.params.get('ether_type') filter_name = module.params.get('filter') icmp_msg_type = module.params.get('icmp_msg_type') if icmp_msg_type is not None: icmp_msg_type = ICMP_MAPPING.get(icmp_msg_type) icmp6_msg_type = module.params.get('icmp6_msg_type') if icmp6_msg_type is not None: icmp6_msg_type = ICMP6_MAPPING.get(icmp6_msg_type) ip_protocol = module.params.get('ip_protocol') state = module.params.get('state') stateful = aci.boolean(module.params.get('stateful')) tenant = module.params.get('tenant') name_alias = module.params.get('name_alias') # validate that dst_port is not passed with dst_start or dst_end if dst_port is not None and (dst_end is not None or dst_start is not None): module.fail_json( msg= "Parameter 'dst_port' cannot be used with 'dst_end' and 'dst_start'" ) elif dst_port is not None: dst_end = dst_port dst_start = dst_port aci.construct_url( root_class=dict( aci_class='fvTenant', aci_rn='tn-{0}'.format(tenant), module_object=tenant, target_filter={'name': tenant}, ), subclass_1=dict( aci_class='vzFilter', aci_rn='flt-{0}'.format(filter_name), module_object=filter_name, target_filter={'name': filter_name}, ), subclass_2=dict( aci_class='vzEntry', aci_rn='e-{0}'.format(entry), module_object=entry, target_filter={'name': entry}, ), ) aci.get_existing() if state == 'present': aci.payload( aci_class='vzEntry', class_config=dict( arpOpc=arp_flag, descr=description, dFromPort=dst_start, dToPort=dst_end, etherT=ether_type, icmpv4T=icmp_msg_type, icmpv6T=icmp6_msg_type, name=entry, prot=ip_protocol, stateful=stateful, nameAlias=name_alias, ), ) aci.get_diff(aci_class='vzEntry') aci.post_config() elif state == 'absent': aci.delete_config() aci.exit_json()