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_bd
17short_description: Manage site-local Bridge Domains (BDs) in schema template
19- Manage site-local BDs 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 BD to manage.
46 - Whether host-based routing is enabled.
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
57- module: mso_schema_site_bd_l3out
58- module: mso_schema_site_bd_subnet
59- module: mso_schema_template_bd
60extends_documentation_fragment: mso
64- name: Add a new site BD
68 password: SomeSecretPassword
74 delegate_to: localhost
76- name: Remove a site BD
80 password: SomeSecretPassword
86 delegate_to: localhost
88- name: Query a specific site BD
92 password: SomeSecretPassword
98 delegate_to: localhost
99 register: query_result
101- name: Query all site BDs
105 password: SomeSecretPassword
110 delegate_to: localhost
111 register: query_result
117from ansible.module_utils.basic import AnsibleModule
118from ansible.module_utils.network.aci.mso import MSOModule, mso_argument_spec
123 argument_spec.update(
124 schema=dict(type=
'str', required=
True),
125 site=dict(type=
'str', required=
True),
126 template=dict(type=
'str', required=
True),
127 bd=dict(type=
'str', aliases=[
'name']),
128 host_route=dict(type=
'bool'),
129 state=dict(type=
'str', default=
'present', choices=[
'absent',
'present',
'query']),
133 argument_spec=argument_spec,
134 supports_check_mode=
True,
136 [
'state',
'absent', [
'bd']],
137 [
'state',
'present', [
'bd']],
141 schema = module.params[
'schema']
142 site = module.params[
'site']
143 template = module.params[
'template']
144 bd = module.params[
'bd']
145 host_route = module.params[
'host_route']
146 state = module.params[
'state']
151 schema_obj = mso.get_obj(
'schemas', displayName=schema)
153 mso.fail_json(msg=
"Provided schema '{0}' does not exist".
format(schema))
155 schema_path =
'schemas/{id}'.
format(**schema_obj)
156 schema_id = schema_obj[
'id']
159 site_id = mso.lookup_site(site)
162 sites = [(s[
'siteId'], s[
'templateName'])
for s
in schema_obj[
'sites']]
163 if (site_id, template)
not in sites:
164 mso.fail_json(msg=
"Provided site/template '{0}-{1}' does not exist. Existing sites/templates: {2}".
format(site, template,
', '.join(sites)))
167 site_idx = sites.index((site_id, template))
169 site_template =
'{0}-{1}'.
format(site_id, template)
172 bd_ref = mso.bd_ref(schema_id=schema_id, template=template, bd=bd)
173 bds = [v[
'bdRef']
for v
in schema_obj[
'sites'][site_idx][
'bds']]
174 if bd
is not None and bd_ref
in bds:
175 bd_idx = bds.index(bd_ref)
176 bd_path =
'/sites/{0}/bds/{1}'.
format(site_template, bd)
177 mso.existing = schema_obj[
'sites'][site_idx][
'bds'][bd_idx]
181 mso.existing = schema_obj[
'sites'][site_idx][
'bds']
182 elif not mso.existing:
183 mso.fail_json(msg=
"BD '{bd}' not found".
format(bd=bd))
186 bds_path =
'/sites/{0}/bds'.
format(site_template)
189 mso.previous = mso.existing
190 if state ==
'absent':
192 mso.sent = mso.existing = {}
193 ops.append(dict(op=
'remove', path=bd_path))
195 elif state ==
'present':
197 if host_route
is None:
203 templateName=template,
206 hostBasedRouting=host_route,
209 mso.sanitize(payload, collate=
True)
212 ops.append(dict(op=
'replace', path=bd_path, value=mso.sent))
214 ops.append(dict(op=
'add', path=bds_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__":