6from __future__
import absolute_import, division, print_function
9ANSIBLE_METADATA = {
'metadata_version':
'1.1',
10 'status': [
'preview'],
11 'supported_by':
'certified'}
15module: aci_contract_subject_to_filter
16short_description: Bind Contract Subjects to Filters (vz:RsSubjFiltAtt)
18- Bind Contract Subjects to Filters on Cisco ACI fabrics.
23 - The name of the contract.
25 aliases: [ contract_name ]
28 - The name of the Filter to bind to the Subject.
30 aliases: [ filter_name ]
33 - Determines if the binding should be set to log.
34 - The APIC defaults to C(none) when unset during creation.
36 choices: [ log, none ]
37 aliases: [ directive ]
40 - The name of the Contract Subject.
42 aliases: [ contract_subject, subject_name ]
45 - Use C(present)
or C(absent)
for adding
or removing.
46 - Use C(query)
for listing an object
or multiple objects.
48 choices: [ absent, present, query ]
52 - The name of the tenant.
55 aliases: [ tenant_name ]
56extends_documentation_fragment: aci
58- The C(tenant), C(contract), C(subject),
and C(filter_name) must exist before using this module
in your playbook.
59 The M(aci_tenant), M(aci_contract), M(aci_contract_subject),
and M(aci_filter) modules can be used
for these.
61- module: aci_contract_subject
63- name: APIC Management Information Model reference
64 description: More information about the internal APIC
class B(vz:RsSubjFiltAtt).
65 link: https://developer.cisco.com/docs/apic-mim-ref/
67- Jacob McGill (
@jmcgill298)
71- name: Add a new contract subject to filer binding
72 aci_contract_subject_to_filter:
75 password: SomeSecretPassword
79 filter: '{{ filter }}'
82 delegate_to: localhost
84- name: Remove an existing contract subject to filter binding
85 aci_contract_subject_to_filter:
88 password: SomeSecretPassword
92 filter:
'{{ filter }}'
95 delegate_to: localhost
97- name: Query a specific contract subject to filter binding
98 aci_contract_subject_to_filter:
101 password: SomeSecretPassword
105 filter:
'{{ filter }}'
107 delegate_to: localhost
108 register: query_result
110- name: Query all contract subject to filter bindings
111 aci_contract_subject_to_filter:
114 password: SomeSecretPassword
119 delegate_to: localhost
120 register: query_result
125 description: The existing configuration from the APIC after the module has finished
133 "descr":
"Production environment",
134 "dn":
"uni/tn-production",
135 "name":
"production",
144 description: The error information
as returned
from the APIC
150 "text":
"unknown managed object class foo"
153 description: The raw output returned by the APIC REST API (xml
or json)
154 returned: parse error
156 sample:
'<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
158 description: The actual/minimal configuration pushed to the APIC
165 "descr":
"Production environment"
170 description: The original configuration
from the APIC before the module has started
178 "descr":
"Production",
179 "dn":
"uni/tn-production",
180 "name":
"production",
189 description: The assembled configuration
from the user-provided parameters
196 "descr":
"Production environment",
202 description: The filter string used
for the request
203 returned: failure
or debug
205 sample: ?rsp-prop-include=config-only
207 description: The HTTP method used
for the request to the APIC
208 returned: failure
or debug
212 description: The HTTP response
from the APIC
213 returned: failure
or debug
215 sample: OK (30 bytes)
217 description: The HTTP status
from the APIC
218 returned: failure
or debug
222 description: The HTTP url used
for the request to the APIC
223 returned: failure
or debug
225 sample: https://10.11.12.13/api/mo/uni/tn-production.json
228from ansible.module_utils.basic import AnsibleModule
229from ansible.module_utils.network.aci.aci import ACIModule, aci_argument_spec
234 argument_spec.update(
235 contract=dict(type='str', aliases=[
'contract_name']),
236 filter=dict(type=
'str', aliases=[
'filter_name']),
237 subject=dict(type=
'str', aliases=[
'contract_subject',
'subject_name']),
238 tenant=dict(type=
'str', aliases=[
'tenant_name']),
239 log=dict(type=
'str', choices=[
'log',
'none'], aliases=[
'directive']),
240 state=dict(type=
'str', default=
'present', choices=[
'absent',
'present',
'query']),
244 argument_spec=argument_spec,
245 supports_check_mode=
True,
247 [
'state',
'absent', [
'contract',
'filter',
'subject',
'tenant']],
248 [
'state',
'present', [
'contract',
'filter',
'subject',
'tenant']],
252 contract = module.params[
'contract']
253 filter_name = module.params[
'filter']
254 log = module.params[
'log']
255 subject = module.params[
'subject']
256 tenant = module.params[
'tenant']
257 state = module.params[
'state']
260 module.params[
'subject_filter'] = filter_name
269 aci_class=
'fvTenant',
270 aci_rn=
'tn-{0}'.
format(tenant),
271 module_object=tenant,
272 target_filter={
'name': tenant},
276 aci_rn=
'brc-{0}'.
format(contract),
277 module_object=contract,
278 target_filter={
'name': contract},
282 aci_rn=
'subj-{0}'.
format(subject),
283 module_object=subject,
284 target_filter={
'name': subject},
287 aci_class=
'vzRsSubjFiltAtt',
288 aci_rn=
'rssubjFiltAtt-{0}'.
format(filter_name),
289 module_object=filter_name,
290 target_filter={
'tnVzFilterName': filter_name},
296 if state ==
'present':
298 aci_class=
'vzRsSubjFiltAtt',
300 tnVzFilterName=filter_name,
305 aci.get_diff(aci_class=
'vzRsSubjFiltAtt')
309 elif state ==
'absent':
313 module.params.pop(
'subject_filter')
318if __name__ ==
"__main__":