7from __future__
import absolute_import, division, print_function
10ANSIBLE_METADATA = {
'metadata_version':
'1.1',
11 'status': [
'preview'],
12 'supported_by':
'community'}
16module: mso_schema_site_vrf_region
17short_description: Manage site-local VRF regions in schema template
19- Manage site-local VRF regions in schema template on Cisco ACI Multi-Site.
21- Dag Wieers (@dagwieers)
26 - The name of the schema.
31 - The name of the site.
36 - The name of the template.
41 - The name of the VRF.
45 - The name of the region to manage.
50 - Use C(present) or C(absent)
for adding
or removing.
51 - Use C(query)
for listing an object
or multiple objects.
53 choices: [ absent, present, query ]
56- module: mso_schema_site_vrf
57- module: mso_schema_template_vrf
58extends_documentation_fragment: mso
62- name: Add a new site VRF region
63 mso_schema_template_vrf_region:
66 password: SomeSecretPassword
73 delegate_to: localhost
75- name: Remove a site VRF region
76 mso_schema_template_vrf_region:
79 password: SomeSecretPassword
86 delegate_to: localhost
88- name: Query a specific site VRF region
89 mso_schema_template_vrf_region:
92 password: SomeSecretPassword
99 delegate_to: localhost
100 register: query_result
102- name: Query all site VRF regions
103 mso_schema_template_vrf_region:
106 password: SomeSecretPassword
112 delegate_to: localhost
113 register: query_result
119from ansible.module_utils.basic import AnsibleModule
120from ansible.module_utils.network.aci.mso import MSOModule, mso_argument_spec
125 argument_spec.update(
126 schema=dict(type=
'str', required=
True),
127 site=dict(type=
'str', required=
True),
128 template=dict(type=
'str', required=
True),
129 vrf=dict(type=
'str', required=
True),
130 region=dict(type=
'str', aliases=[
'name']),
131 state=dict(type=
'str', default=
'present', choices=[
'absent',
'present',
'query']),
135 argument_spec=argument_spec,
136 supports_check_mode=
True,
138 [
'state',
'absent', [
'region']],
139 [
'state',
'present', [
'region']],
143 schema = module.params[
'schema']
144 site = module.params[
'site']
145 template = module.params[
'template']
146 vrf = module.params[
'vrf']
147 region = module.params[
'region']
148 state = module.params[
'state']
153 schema_obj = mso.get_obj(
'schemas', displayName=schema)
155 mso.fail_json(msg=
"Provided schema '{0}' does not exist".
format(schema))
157 schema_path =
'schemas/{id}'.
format(**schema_obj)
158 schema_id = schema_obj[
'id']
161 site_id = mso.lookup_site(site)
164 sites = [(s[
'siteId'], s[
'templateName'])
for s
in schema_obj[
'sites']]
165 if (site_id, template)
not in sites:
166 mso.fail_json(msg=
"Provided site/template '{0}-{1}' does not exist. Existing sites/templates: {2}".
format(site, template,
', '.join(sites)))
169 site_idx = sites.index((site_id, template))
171 site_template =
'{0}-{1}'.
format(site_id, template)
174 vrf_ref = mso.vrf_ref(schema_id=schema_id, template=template, vrf=vrf)
175 vrfs = [v[
'vrfRef']
for v
in schema_obj[
'sites'][site_idx][
'vrfs']]
176 if vrf_ref
not in vrfs:
177 mso.fail_json(msg=
"Provided vrf '{0}' does not exist. Existing vrfs: {1}".
format(vrf,
', '.join(vrfs)))
178 vrf_idx = vrfs.index(vrf_ref)
181 regions = [r[
'name']
for r
in schema_obj[
'sites'][site_idx][
'vrfs'][vrf_idx][
'regions']]
182 if region
is not None and region
in regions:
183 region_idx = regions.index(region)
184 region_path =
'/sites/{0}/vrfs/{1}/regions/{2}'.
format(site_template, vrf, region)
185 mso.existing = schema_obj[
'sites'][site_idx][
'vrfs'][vrf_idx][
'regions'][region_idx]
189 mso.existing = schema_obj[
'sites'][site_idx][
'vrfs'][vrf_idx][
'regions']
190 elif not mso.existing:
191 mso.fail_json(msg=
"Region '{region}' not found".
format(region=region))
194 regions_path =
'/sites/{0}/vrfs/{1}/regions'.
format(site_template, vrf)
197 mso.previous = mso.existing
198 if state ==
'absent':
200 mso.sent = mso.existing = {}
201 ops.append(dict(op=
'remove', path=region_path))
203 elif state ==
'present':
209 mso.sanitize(payload, collate=
True)
212 ops.append(dict(op=
'replace', path=region_path, value=mso.sent))
214 ops.append(dict(op=
'add', path=regions_path +
'/-', value=mso.sent))
216 mso.existing = mso.proposed
218 if not module.check_mode:
219 mso.request(schema_path, method=
'PATCH', data=ops)
224if __name__ ==
"__main__":