6from __future__
import absolute_import, division, print_function
9ANSIBLE_METADATA = {
'metadata_version':
'1.1',
10 'status': [
'preview'],
11 'supported_by':
'certified'}
15module: aci_filter_entry
16short_description: Manage filter entries (vz:Entry)
18- Manage filter entries for a filter on Cisco ACI fabrics.
23 - The arp flag to use when the ether_type is arp.
24 - The APIC defaults to C(unspecified) when unset during creation.
26 choices: [ arp_reply, arp_request, unspecified ]
29 - Description
for the Filter Entry.
34 - Used to set both destination start
and end ports to the same value when ip_protocol
is tcp
or udp.
35 - Accepted values are any valid TCP/UDP port range.
36 - The APIC defaults to C(unspecified) when unset during creation.
40 - Used to set the destination end port when ip_protocol
is tcp
or udp.
41 - Accepted values are any valid TCP/UDP port range.
42 - The APIC defaults to C(unspecified) when unset during creation.
46 - Used to set the destination start port when ip_protocol
is tcp
or udp.
47 - Accepted values are any valid TCP/UDP port range.
48 - The APIC defaults to C(unspecified) when unset during creation.
52 - Then name of the Filter Entry.
54 aliases: [ entry_name, filter_entry, name ]
58 - The APIC defaults to C(unspecified) when unset during creation.
60 choices: [ arp, fcoe, ip, mac_security, mpls_ucast, trill, unspecified ]
63 - The name of Filter that the entry should belong to.
65 aliases: [ filter_name ]
68 - ICMPv4 message type; used when ip_protocol
is icmp.
69 - The APIC defaults to C(unspecified) when unset during creation.
71 choices: [ dst_unreachable, echo, echo_reply, src_quench, time_exceeded, unspecified ]
74 - ICMPv6 message type; used when ip_protocol
is icmpv6.
75 - The APIC defaults to C(unspecified) when unset during creation.
77 choices: [ dst_unreachable, echo_request, echo_reply, neighbor_advertisement, neighbor_solicitation, redirect, time_exceeded, unspecified ]
80 - The IP Protocol type when ether_type
is ip.
81 - The APIC defaults to C(unspecified) when unset during creation.
83 choices: [ eigrp, egp, icmp, icmpv6, igmp, igp, l2tp, ospfigp, pim, tcp, udp, unspecified ]
86 - present, absent, query
89 choices: [ absent, present, query ]
92 - Determines the statefulness of the filter entry.
96 - The name of the tenant.
98 aliases: [ tenant_name ]
99extends_documentation_fragment: aci
101- The C(tenant)
and C(filter) used must exist before using this module
in your playbook.
102 The M(aci_tenant)
and M(aci_filter) modules can be used
for this.
106- name: APIC Management Information Model reference
107 description: More information about the internal APIC
class B(vz:Entry).
108 link: https://developer.cisco.com/docs/apic-mim-ref/
110- Jacob McGill (
@jmcgill298)
115 host: "{{ inventory_hostname }}"
116 username:
"{{ user }}"
117 password:
"{{ pass }}"
120 tenant:
"{{ tenant }}"
121 ether_name:
"{{ ether_name }}"
122 icmp_msg_type:
"{{ icmp_msg_type }}"
123 filter:
"{{ filter }}"
125 delegate_to: localhost
130 description: The existing configuration from the APIC after the module has finished
138 "descr":
"Production environment",
139 "dn":
"uni/tn-production",
140 "name":
"production",
149 description: The error information
as returned
from the APIC
155 "text":
"unknown managed object class foo"
158 description: The raw output returned by the APIC REST API (xml
or json)
159 returned: parse error
161 sample:
'<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
163 description: The actual/minimal configuration pushed to the APIC
170 "descr":
"Production environment"
175 description: The original configuration
from the APIC before the module has started
183 "descr":
"Production",
184 "dn":
"uni/tn-production",
185 "name":
"production",
194 description: The assembled configuration
from the user-provided parameters
201 "descr":
"Production environment",
207 description: The filter string used
for the request
208 returned: failure
or debug
210 sample: ?rsp-prop-include=config-only
212 description: The HTTP method used
for the request to the APIC
213 returned: failure
or debug
217 description: The HTTP response
from the APIC
218 returned: failure
or debug
220 sample: OK (30 bytes)
222 description: The HTTP status
from the APIC
223 returned: failure
or debug
227 description: The HTTP url used
for the request to the APIC
228 returned: failure
or debug
230 sample: https://10.11.12.13/api/mo/uni/tn-production.json
233from ansible.module_utils.basic import AnsibleModule
234from ansible.module_utils.network.aci.aci import ACIModule, aci_argument_spec
236VALID_ARP_FLAGS = ['arp_reply', 'arp_request', 'unspecified']
237VALID_ETHER_TYPES = ['arp', 'fcoe', 'ip', 'mac_security', 'mpls_ucast', 'trill', 'unspecified']
238VALID_ICMP_TYPES = ['dst_unreachable', 'echo', 'echo_reply', 'src_quench', 'time_exceeded', 'unspecified']
239VALID_ICMP6_TYPES = ['dst_unreachable', 'echo_request', 'echo_reply', 'neighbor_advertisement',
240 'neighbor_solicitation',
'redirect',
'time_exceeded',
'unspecified']
241VALID_IP_PROTOCOLS = [
'eigrp',
'egp',
'icmp',
'icmpv6',
'igmp',
'igp',
'l2tp',
'ospfigp',
'pim',
'tcp',
'udp',
'unspecified']
244ARP_FLAG_MAPPING = dict(arp_reply=
'reply', arp_request=
'req', unspecified=
None)
245FILTER_PORT_MAPPING = {
'443':
'https',
'25':
'smtp',
'80':
'http',
'20':
'ftpData',
'53':
'dns',
'110':
'pop3',
'554':
'rtsp'}
246ICMP_MAPPING = {
'dst_unreachable':
'dst-unreach',
'echo':
'echo',
'echo_reply':
'echo-rep',
'src_quench':
'src-quench',
247 'time_exceeded':
'time-exceeded',
'unspecified':
'unspecified',
'echo-rep':
'echo-rep',
'dst-unreach':
'dst-unreach'}
248ICMP6_MAPPING = dict(dst_unreachable=
'dst-unreach', echo_request=
'echo-req', echo_reply=
'echo-rep', neighbor_advertisement=
'nbr-advert',
249 neighbor_solicitation=
'nbr-solicit', redirect=
'redirect', time_exceeded=
'time-exceeded', unspecified=
'unspecified')
254 argument_spec.update(
255 arp_flag=dict(type=
'str', choices=VALID_ARP_FLAGS),
256 description=dict(type=
'str', aliases=[
'descr']),
257 dst_port=dict(type=
'str'),
258 dst_port_end=dict(type=
'str'),
259 dst_port_start=dict(type=
'str'),
260 entry=dict(type=
'str', aliases=[
'entry_name',
'filter_entry',
'name']),
261 ether_type=dict(choices=VALID_ETHER_TYPES, type=
'str'),
262 filter=dict(type=
'str', aliases=[
'filter_name']),
263 icmp_msg_type=dict(type=
'str', choices=VALID_ICMP_TYPES),
264 icmp6_msg_type=dict(type=
'str', choices=VALID_ICMP6_TYPES),
265 ip_protocol=dict(choices=VALID_IP_PROTOCOLS, type=
'str'),
266 state=dict(type=
'str', default=
'present', choices=[
'absent',
'present',
'query']),
267 stateful=dict(type=
'bool'),
268 tenant=dict(type=
'str', aliases=[
'tenant_name']),
272 argument_spec=argument_spec,
273 supports_check_mode=
True,
275 [
'state',
'absent', [
'entry',
'filter',
'tenant']],
276 [
'state',
'present', [
'entry',
'filter',
'tenant']],
282 arp_flag = module.params[
'arp_flag']
283 if arp_flag
is not None:
284 arp_flag = ARP_FLAG_MAPPING[arp_flag]
285 description = module.params[
'description']
286 dst_port = module.params[
'dst_port']
287 if dst_port
in FILTER_PORT_MAPPING.keys():
288 dst_port = FILTER_PORT_MAPPING[dst_port]
289 dst_end = module.params[
'dst_port_end']
290 if dst_end
in FILTER_PORT_MAPPING.keys():
291 dst_end = FILTER_PORT_MAPPING[dst_end]
292 dst_start = module.params[
'dst_port_start']
293 if dst_start
in FILTER_PORT_MAPPING.keys():
294 dst_start = FILTER_PORT_MAPPING[dst_start]
295 entry = module.params[
'entry']
296 ether_type = module.params[
'ether_type']
297 filter_name = module.params[
'filter']
298 icmp_msg_type = module.params[
'icmp_msg_type']
299 if icmp_msg_type
is not None:
300 icmp_msg_type = ICMP_MAPPING[icmp_msg_type]
301 icmp6_msg_type = module.params[
'icmp6_msg_type']
302 if icmp6_msg_type
is not None:
303 icmp6_msg_type = ICMP6_MAPPING[icmp6_msg_type]
304 ip_protocol = module.params[
'ip_protocol']
305 state = module.params[
'state']
306 stateful = aci.boolean(module.params[
'stateful'])
307 tenant = module.params[
'tenant']
310 if dst_port
is not None and (dst_end
is not None or dst_start
is not None):
311 module.fail_json(msg=
"Parameter 'dst_port' cannot be used with 'dst_end' and 'dst_start'")
312 elif dst_port
is not None:
318 aci_class=
'fvTenant',
319 aci_rn=
'tn-{0}'.
format(tenant),
320 module_object=tenant,
321 target_filter={
'name': tenant},
324 aci_class=
'vzFilter',
325 aci_rn=
'flt-{0}'.
format(filter_name),
326 module_object=filter_name,
327 target_filter={
'name': filter_name},
331 aci_rn=
'e-{0}'.
format(entry),
333 target_filter={
'name': entry},
339 if state ==
'present':
348 icmpv4T=icmp_msg_type,
349 icmpv6T=icmp6_msg_type,
356 aci.get_diff(aci_class=
'vzEntry')
360 elif state ==
'absent':
366if __name__ ==
"__main__":