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_anp
17short_description: Manage site-local Application Network Profiles (ANPs) in schema template
19- Manage site-local ANPs 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 ANP 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_site_anp_epg
54- module: mso_schema_template_anp
55extends_documentation_fragment: mso
59- name: Add a new site ANP
63 password: SomeSecretPassword
69 delegate_to: localhost
71- name: Remove a site ANP
75 password: SomeSecretPassword
81 delegate_to: localhost
83- name: Query a specific site ANPs
87 password: SomeSecretPassword
92 delegate_to: localhost
93 register: query_result
95- name: Query all site ANPs
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, issubset
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 anp=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', [
'anp']],
130 [
'state',
'present', [
'anp']],
134 schema = module.params[
'schema']
135 site = module.params[
'site']
136 template = module.params[
'template']
137 anp = module.params[
'anp']
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 anp_ref = mso.anp_ref(schema_id=schema_id, template=template, anp=anp)
165 anps = [a[
'anpRef']
for a
in schema_obj[
'sites'][site_idx][
'anps']]
167 if anp
is not None and anp_ref
in anps:
168 anp_idx = anps.index(anp_ref)
169 anp_path =
'/sites/{0}/anps/{1}'.
format(site_template, anp)
170 mso.existing = schema_obj[
'sites'][site_idx][
'anps'][anp_idx]
174 mso.existing = schema_obj[
'sites'][site_idx][
'anps']
175 elif not mso.existing:
176 mso.fail_json(msg=
"ANP '{anp}' not found".
format(anp=anp))
179 anps_path =
'/sites/{0}/anps'.
format(site_template)
182 mso.previous = mso.existing
183 if state ==
'absent':
185 mso.sent = mso.existing = {}
186 ops.append(dict(op=
'remove', path=anp_path))
188 elif state ==
'present':
193 templateName=template,
198 mso.sanitize(payload, collate=
True)
201 ops.append(dict(op=
'add', path=anps_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__":