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
17short_description: Manage site-local VRFs in schema template
19- Manage site-local VRFs 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 to manage.
46 - Use C(present) or C(absent)
for adding
or removing.
47 - Use C(query)
for listing an object
or multiple objects.
49 choices: [ absent, present, query ]
52- module: mso_schema_site
53- module: mso_schema_template_vrf
54extends_documentation_fragment: mso
58- name: Add a new site VRF
62 password: SomeSecretPassword
68 delegate_to: localhost
70- name: Remove a site VRF
74 password: SomeSecretPassword
80 delegate_to: localhost
82- name: Query a specific site VRF
86 password: SomeSecretPassword
92 delegate_to: localhost
93 register: query_result
95- name: Query all site VRFs
99 password: SomeSecretPassword
104 delegate_to: localhost
105 register: query_result
111from ansible.module_utils.basic import AnsibleModule
112from ansible.module_utils.network.aci.mso import MSOModule, mso_argument_spec
117 argument_spec.update(
118 schema=dict(type=
'str', required=
True),
119 site=dict(type=
'str', required=
True),
120 template=dict(type=
'str', required=
True),
121 vrf=dict(type=
'str', aliases=[
'name']),
122 state=dict(type=
'str', default=
'present', choices=[
'absent',
'present',
'query']),
126 argument_spec=argument_spec,
127 supports_check_mode=
True,
129 [
'state',
'absent', [
'vrf']],
130 [
'state',
'present', [
'vrf']],
134 schema = module.params[
'schema']
135 site = module.params[
'site']
136 template = module.params[
'template']
137 vrf = module.params[
'vrf']
138 state = module.params[
'state']
143 schema_obj = mso.get_obj(
'schemas', displayName=schema)
145 mso.fail_json(msg=
"Provided schema '{0}' does not exist".
format(schema))
147 schema_path =
'schemas/{id}'.
format(**schema_obj)
148 schema_id = schema_obj[
'id']
151 site_id = mso.lookup_site(site)
154 sites = [(s[
'siteId'], s[
'templateName'])
for s
in schema_obj[
'sites']]
155 if (site_id, template)
not in sites:
156 mso.fail_json(msg=
"Provided site/template '{0}-{1}' does not exist. Existing sites/templates: {2}".
format(site, template,
', '.join(sites)))
159 site_idx = sites.index((site_id, template))
161 site_template =
'{0}-{1}'.
format(site_id, template)
164 vrf_ref = mso.vrf_ref(schema_id=schema_id, template=template, vrf=vrf)
165 vrfs = [v[
'vrfRef']
for v
in schema_obj[
'sites'][site_idx][
'vrfs']]
166 if vrf
is not None and vrf_ref
in vrfs:
167 vrf_idx = vrfs.index(vrf_ref)
168 vrf_path =
'/sites/{0}/vrfs/{1}'.
format(site_template, vrf)
169 mso.existing = schema_obj[
'sites'][site_idx][
'vrfs'][vrf_idx]
173 mso.existing = schema_obj[
'sites'][site_idx][
'vrfs']
174 elif not mso.existing:
175 mso.fail_json(msg=
"VRF '{vrf}' not found".
format(vrf=vrf))
178 vrfs_path =
'/sites/{0}/vrfs'.
format(site_template)
181 mso.previous = mso.existing
182 if state ==
'absent':
184 mso.sent = mso.existing = {}
185 ops.append(dict(op=
'remove', path=vrf_path))
187 elif state ==
'present':
191 templateName=template,
196 mso.sanitize(payload, collate=
True)
199 ops.append(dict(op=
'replace', path=vrf_path, value=mso.sent))
201 ops.append(dict(op=
'add', path=vrfs_path +
'/-', value=mso.sent))
203 mso.existing = mso.proposed
205 if not module.check_mode:
206 mso.request(schema_path, method=
'PATCH', data=ops)
211if __name__ ==
"__main__":