7from __future__
import absolute_import, division, print_function
10ANSIBLE_METADATA = {
'metadata_version':
'1.1',
11 'status': [
'preview'],
12 'supported_by':
'community'}
16module: mso_schema_template_anp_epg
17short_description: Manage Endpoint Groups (EPGs) in schema templates
19- Manage EPGs in schema templates on Cisco ACI Multi-Site.
21- Dag Wieers (@dagwieers)
26 - The name of the schema.
31 - The name of the template.
36 - The name of the ANP.
41 - The name of the EPG to manage.
46 - The name as displayed on the MSO web interface.
54 - The BD associated to this ANP.
59 - The name of the BD to associate
with.
64 - The schema that defines the referenced BD.
65 - If this parameter
is unspecified, it defaults to the current schema.
69 - The template that defines the referenced BD.
74 - The VRF associated to this ANP.
79 - The name of the VRF to associate
with.
84 - The schema that defines the referenced VRF.
85 - If this parameter
is unspecified, it defaults to the current schema.
89 - The template that defines the referenced VRF.
93 - The subnets associated to this ANP.
98 - The IP range
in CIDR notation.
103 - The description of this subnet.
107 - The scope of the subnet.
109 choices: [ private, public ]
112 - Whether this subnet
is shared between VRFs.
116 - Whether this subnet has a default gateway.
120 - Whether this
is a USEG EPG.
128 - Whether intra EPG isolation
is enforced.
129 - When
not specified, this parameter defaults to C(unenforced).
131 choices: [ enforced, unenforced ]
132 intersite_multicaste_source:
134 - Whether intersite multicast source
is enabled.
135 - When
not specified, this parameter defaults to C(no).
139 - Whether this EPG
is added to preferred group
or not.
140 - When
not specified, this parameter defaults to C(no).
145 - Use C(present)
or C(absent)
for adding
or removing.
146 - Use C(query)
for listing an object
or multiple objects.
148 choices: [ absent, present, query ]
151- module: mso_schema_template_anp
152- module: mso_schema_template_anp_epg_subnet
153- module: mso_schema_template_bd
154- module: mso_schema_template_contract_filter
155extends_documentation_fragment: mso
160 mso_schema_template_anp_epg:
163 password: SomeSecretPassword
173 delegate_to: localhost
175- name: Add a new EPG with preferred group.
176 mso_schema_template_anp_epg:
179 password: SomeSecretPassword
186 delegate_to: localhost
189 mso_schema_template_anp_epg:
192 password: SomeSecretPassword
202 delegate_to: localhost
204- name: Query a specific EPG
205 mso_schema_template_anp_epg:
208 password: SomeSecretPassword
218 delegate_to: localhost
219 register: query_result
221- name: Query all EPGs
222 mso_schema_template_anp_epg:
225 password: SomeSecretPassword
235 delegate_to: localhost
236 register: query_result
242from ansible.module_utils.basic import AnsibleModule
243from ansible.module_utils.network.aci.mso import MSOModule, mso_argument_spec, mso_reference_spec, mso_subnet_spec, issubset
248 argument_spec.update(
249 schema=dict(type=
'str', required=
True),
250 template=dict(type=
'str', required=
True),
251 anp=dict(type=
'str', required=
True),
252 epg=dict(type=
'str', aliases=[
'name']),
255 display_name=dict(type=
'str'),
256 useg_epg=dict(type=
'bool'),
257 intra_epg_isolation=dict(type=
'str', choices=[
'enforced',
'unenforced']),
258 intersite_multicaste_source=dict(type=
'bool'),
260 state=dict(type=
'str', default=
'present', choices=[
'absent',
'present',
'query']),
261 preferred_group=dict(type=
'bool'),
265 argument_spec=argument_spec,
266 supports_check_mode=
True,
268 [
'state',
'absent', [
'epg']],
269 [
'state',
'present', [
'epg']],
273 schema = module.params[
'schema']
274 template = module.params[
'template']
275 anp = module.params[
'anp']
276 epg = module.params[
'epg']
277 display_name = module.params[
'display_name']
278 bd = module.params[
'bd']
279 vrf = module.params[
'vrf']
280 useg_epg = module.params[
'useg_epg']
281 intra_epg_isolation = module.params[
'intra_epg_isolation']
282 intersite_multicaste_source = module.params[
'intersite_multicaste_source']
283 subnets = module.params[
'subnets']
284 state = module.params[
'state']
285 preferred_group = module.params[
'preferred_group']
290 schema_obj = mso.get_obj(
'schemas', displayName=schema)
292 schema_id = schema_obj[
'id']
294 mso.fail_json(msg=
"Provided schema '{0}' does not exist".
format(schema))
296 schema_path =
'schemas/{id}'.
format(**schema_obj)
299 templates = [t[
'name']
for t
in schema_obj[
'templates']]
300 if template
not in templates:
301 mso.fail_json(msg=
"Provided template '{0}' does not exist. Existing templates: {1}".
format(template,
', '.join(templates)))
302 template_idx = templates.index(template)
305 anps = [a[
'name']
for a
in schema_obj[
'templates'][template_idx][
'anps']]
307 mso.fail_json(msg=
"Provided anp '{0}' does not exist. Existing anps: {1}".
format(anp,
', '.join(anps)))
308 anp_idx = anps.index(anp)
311 epgs = [e[
'name']
for e
in schema_obj[
'templates'][template_idx][
'anps'][anp_idx][
'epgs']]
312 if epg
is not None and epg
in epgs:
313 epg_idx = epgs.index(epg)
314 mso.existing = schema_obj[
'templates'][template_idx][
'anps'][anp_idx][
'epgs'][epg_idx]
318 mso.existing = schema_obj[
'templates'][template_idx][
'anps'][anp_idx][
'epgs']
319 elif not mso.existing:
320 mso.fail_json(msg=
"EPG '{epg}' not found".
format(epg=epg))
323 epgs_path =
'/templates/{0}/anps/{1}/epgs'.
format(template, anp)
324 epg_path =
'/templates/{0}/anps/{1}/epgs/{2}'.
format(template, anp, epg)
327 mso.previous = mso.existing
328 if state ==
'absent':
330 mso.sent = mso.existing = {}
331 ops.append(dict(op=
'remove', path=epg_path))
333 elif state ==
'present':
334 bd_ref = mso.make_reference(bd,
'bd', schema_id, template)
335 vrf_ref = mso.make_reference(vrf,
'vrf', schema_id, template)
336 subnets = mso.make_subnets(subnets)
338 if display_name
is None and not mso.existing:
343 displayName=display_name,
345 intraEpg=intra_epg_isolation,
346 proxyArp=intersite_multicaste_source,
349 contractRelationships=[],
352 preferredGroup=preferred_group,
356 mso.sanitize(payload, collate=
True)
359 ops.append(dict(op=
'replace', path=epg_path, value=mso.sent))
361 ops.append(dict(op=
'add', path=epgs_path +
'/-', value=mso.sent))
363 mso.existing = mso.proposed
365 if not module.check_mode:
366 mso.request(schema_path, method=
'PATCH', data=ops)
371if __name__ ==
"__main__":