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_vrf
17short_description: Manage VRFs in schema templates
19- Manage VRFs 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 VRF to manage.
41 - The name as displayed on the MSO web interface.
45 - Whether to enable L3 multicast.
49 - Use C(present)
or C(absent)
for adding
or removing.
50 - Use C(query)
for listing an object
or multiple objects.
52 choices: [ absent, present, query ]
54extends_documentation_fragment: mso
59 mso_schema_template_vrf:
62 password: SomeSecretPassword
67 delegate_to: localhost
70 mso_schema_template_vrf:
73 password: SomeSecretPassword
78 delegate_to: localhost
80- name: Query a specific VRFs
81 mso_schema_template_vrf:
84 password: SomeSecretPassword
89 delegate_to: localhost
90 register: query_result
93 mso_schema_template_vrf:
96 password: SomeSecretPassword
100 delegate_to: localhost
101 register: query_result
107from ansible.module_utils.basic import AnsibleModule
108from ansible.module_utils.network.aci.mso import MSOModule, mso_argument_spec, mso_reference_spec, issubset
113 argument_spec.update(
114 schema=dict(type=
'str', required=
True),
115 template=dict(type=
'str', required=
True),
116 vrf=dict(type=
'str', aliases=[
'name']),
117 display_name=dict(type=
'str'),
118 layer3_multicast=dict(type=
'bool'),
119 state=dict(type=
'str', default=
'present', choices=[
'absent',
'present',
'query']),
123 argument_spec=argument_spec,
124 supports_check_mode=
True,
126 [
'state',
'absent', [
'vrf']],
127 [
'state',
'present', [
'vrf']],
131 schema = module.params[
'schema']
132 template = module.params[
'template']
133 vrf = module.params[
'vrf']
134 display_name = module.params[
'display_name']
135 layer3_multicast = module.params[
'layer3_multicast']
136 state = module.params[
'state']
141 schema_obj = mso.get_obj(
'schemas', displayName=schema)
143 mso.fail_json(msg=
"Provided schema '{0}' does not exist".
format(schema))
145 schema_path =
'schemas/{id}'.
format(**schema_obj)
148 templates = [t[
'name']
for t
in schema_obj[
'templates']]
149 if template
not in templates:
150 mso.fail_json(msg=
"Provided template '{0}' does not exist. Existing templates: {1}".
format(template,
', '.join(templates)))
151 template_idx = templates.index(template)
154 vrfs = [v[
'name']
for v
in schema_obj[
'templates'][template_idx][
'vrfs']]
156 if vrf
is not None and vrf
in vrfs:
157 vrf_idx = vrfs.index(vrf)
158 mso.existing = schema_obj[
'templates'][template_idx][
'vrfs'][vrf_idx]
162 mso.existing = schema_obj[
'templates'][template_idx][
'vrfs']
163 elif not mso.existing:
164 mso.fail_json(msg=
"VRF '{vrf}' not found".
format(vrf=vrf))
167 vrfs_path =
'/templates/{0}/vrfs'.
format(template)
168 vrf_path =
'/templates/{0}/vrfs/{1}'.
format(template, vrf)
171 mso.previous = mso.existing
172 if state ==
'absent':
174 mso.sent = mso.existing = {}
175 ops.append(dict(op=
'remove', path=vrf_path))
177 elif state ==
'present':
178 if display_name
is None and not mso.existing:
183 displayName=display_name,
184 l3MCast=layer3_multicast,
189 mso.sanitize(payload, collate=
True)
192 ops.append(dict(op=
'replace', path=vrf_path, value=mso.sent))
194 ops.append(dict(op=
'add', path=vrfs_path +
'/-', value=mso.sent))
196 mso.existing = mso.proposed
198 if not module.check_mode:
199 mso.request(schema_path, method=
'PATCH', data=ops)
204if __name__ ==
"__main__":