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_bd
17short_description: Manage Bridge Domains (BDs) in schema templates
19- Manage BDs 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 BD to manage.
41 - The name as displayed on the MSO web interface.
45 - The VRF associated to this BD. This
is required only when creating a new BD.
50 - The name of the VRF to associate
with.
55 - The subnets associated to this BD.
60 - The IP range
in CIDR notation.
65 - The description of this subnet.
69 - The scope of the subnet.
71 choices: [ private, public ]
74 - Whether this subnet
is shared between VRFs.
78 - Whether this subnet has a default gateway.
80 intersite_bum_traffic:
82 - Whether to allow intersite BUM traffic.
84 optimize_wan_bandwidth:
86 - Whether to optimize WAN bandwidth.
90 - Whether to enable L2 stretch.
92 layer2_unknown_unicast:
94 - Layer2 unknown unicast.
96 choices: [ flood, proxy ]
99 - Whether to enable L3 multicast.
103 - Use C(present)
or C(absent)
for adding
or removing.
104 - Use C(query)
for listing an object
or multiple objects.
106 choices: [ absent, present, query ]
108extends_documentation_fragment: mso
113 mso_schema_template_bd:
116 password: SomeSecretPassword
123 delegate_to: localhost
126 mso_schema_template_bd:
129 password: SomeSecretPassword
134 delegate_to: localhost
136- name: Query a specific BDs
137 mso_schema_template_bd:
140 password: SomeSecretPassword
145 delegate_to: localhost
146 register: query_result
149 mso_schema_template_bd:
152 password: SomeSecretPassword
156 delegate_to: localhost
157 register: query_result
163from ansible.module_utils.basic import AnsibleModule
164from ansible.module_utils.network.aci.mso import MSOModule, mso_argument_spec, mso_reference_spec, mso_subnet_spec
169 argument_spec.update(
170 schema=dict(type=
'str', required=
True),
171 template=dict(type=
'str', required=
True),
172 bd=dict(type=
'str', aliases=[
'name']),
173 display_name=dict(type=
'str'),
174 intersite_bum_traffic=dict(type=
'bool'),
175 optimize_wan_bandwidth=dict(type=
'bool'),
176 layer2_stretch=dict(type=
'bool'),
177 layer2_unknown_unicast=dict(type=
'str', choices=[
'flood',
'proxy']),
178 layer3_multicast=dict(type=
'bool'),
181 state=dict(type=
'str', default=
'present', choices=[
'absent',
'present',
'query']),
185 argument_spec=argument_spec,
186 supports_check_mode=
True,
188 [
'state',
'absent', [
'bd']],
189 [
'state',
'present', [
'bd',
'vrf']],
193 schema = module.params[
'schema']
194 template = module.params[
'template']
195 bd = module.params[
'bd']
196 display_name = module.params[
'display_name']
197 intersite_bum_traffic = module.params[
'intersite_bum_traffic']
198 optimize_wan_bandwidth = module.params[
'optimize_wan_bandwidth']
199 layer2_stretch = module.params[
'layer2_stretch']
200 layer2_unknown_unicast = module.params[
'layer2_unknown_unicast']
201 layer3_multicast = module.params[
'layer3_multicast']
202 vrf = module.params[
'vrf']
203 subnets = module.params[
'subnets']
204 state = module.params[
'state']
209 schema_obj = mso.get_obj(
'schemas', displayName=schema)
211 schema_id = schema_obj[
'id']
213 mso.fail_json(msg=
"Provided schema '{0}' does not exist".
format(schema))
215 schema_path =
'schemas/{id}'.
format(**schema_obj)
218 templates = [t[
'name']
for t
in schema_obj[
'templates']]
219 if template
not in templates:
220 mso.fail_json(msg=
"Provided template '{0}' does not exist. Existing templates: {1}".
format(template,
', '.join(templates)))
221 template_idx = templates.index(template)
224 bds = [b[
'name']
for b
in schema_obj[
'templates'][template_idx][
'bds']]
226 if bd
is not None and bd
in bds:
227 bd_idx = bds.index(bd)
228 mso.existing = schema_obj[
'templates'][template_idx][
'bds'][bd_idx]
232 mso.existing = schema_obj[
'templates'][template_idx][
'bds']
233 elif not mso.existing:
234 mso.fail_json(msg=
"BD '{bd}' not found".
format(bd=bd))
237 bds_path =
'/templates/{0}/bds'.
format(template)
238 bd_path =
'/templates/{0}/bds/{1}'.
format(template, bd)
241 mso.previous = mso.existing
242 if state ==
'absent':
244 mso.sent = mso.existing = {}
245 ops.append(dict(op=
'remove', path=bd_path))
247 elif state ==
'present':
248 vrf_ref = mso.make_reference(vrf,
'vrf', schema_id, template)
249 subnets = mso.make_subnets(subnets)
251 if display_name
is None and not mso.existing:
253 if subnets
is None and not mso.existing:
258 displayName=display_name,
259 intersiteBumTrafficAllow=intersite_bum_traffic,
260 optimizeWanBandwidth=optimize_wan_bandwidth,
261 l2UnknownUnicast=layer2_unknown_unicast,
262 l2Stretch=layer2_stretch,
263 l3MCast=layer3_multicast,
268 mso.sanitize(payload, collate=
True)
271 ops.append(dict(op=
'replace', path=bd_path, value=mso.sent))
273 ops.append(dict(op=
'add', path=bds_path +
'/-', value=mso.sent))
275 mso.existing = mso.proposed
277 if not module.check_mode:
278 mso.request(schema_path, method=
'PATCH', data=ops)
283if __name__ ==
"__main__":