6from __future__
import absolute_import, division, print_function
9ANSIBLE_METADATA = {
'metadata_version':
'1.1',
10 'status': [
'preview'],
11 'supported_by':
'certified'}
16short_description: Manage encap pools (fvns:VlanInstP, fvns:VxlanInstP, fvns:VsanInstP)
18- Manage vlan, vxlan, and vsan pools on Cisco ACI fabrics.
23 - Description for the C(pool).
28 - The name of the pool.
30 aliases: [ name, pool_name ]
33 - The method used
for allocating encaps to resources.
34 - Only vlan
and vsan support allocation modes.
36 choices: [ dynamic, static ]
37 aliases: [ allocation_mode, mode ]
40 - The encap type of C(pool).
44 choices: [ vlan, vsan, vxlan ]
47 - Use C(present)
or C(absent)
for adding
or removing.
48 - Use C(query)
for listing an object
or multiple objects.
50 choices: [ absent, present, query ]
52extends_documentation_fragment: aci
54- module: aci_encap_pool_range
55- module: aci_vlan_pool
56- name: APIC Management Information Model reference
57 description: More information about the internal APIC classes B(fvns:VlanInstP),
58 B(fvns:VxlanInstP)
and B(fvns:VsanInstP)
59 link: https://developer.cisco.com/docs/apic-mim-ref/
61- Jacob McGill (
@jmcgill298)
65- name: Add a new vlan pool
69 password: SomeSecretPassword
72 description: Production VLANs
74 delegate_to: localhost
76- name: Remove a vlan pool
80 password: SomeSecretPassword
84 delegate_to: localhost
86- name: Query a vlan pool
90 password: SomeSecretPassword
94 delegate_to: localhost
95 register: query_result
97- name: Query all vlan pools
101 password: SomeSecretPassword
104 delegate_to: localhost
105 register: query_result
110 description: The existing configuration from the APIC after the module has finished
118 "descr":
"Production environment",
119 "dn":
"uni/tn-production",
120 "name":
"production",
129 description: The error information
as returned
from the APIC
135 "text":
"unknown managed object class foo"
138 description: The raw output returned by the APIC REST API (xml
or json)
139 returned: parse error
141 sample:
'<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
143 description: The actual/minimal configuration pushed to the APIC
150 "descr":
"Production environment"
155 description: The original configuration
from the APIC before the module has started
163 "descr":
"Production",
164 "dn":
"uni/tn-production",
165 "name":
"production",
174 description: The assembled configuration
from the user-provided parameters
181 "descr":
"Production environment",
187 description: The filter string used
for the request
188 returned: failure
or debug
190 sample: ?rsp-prop-include=config-only
192 description: The HTTP method used
for the request to the APIC
193 returned: failure
or debug
197 description: The HTTP response
from the APIC
198 returned: failure
or debug
200 sample: OK (30 bytes)
202 description: The HTTP status
from the APIC
203 returned: failure
or debug
207 description: The HTTP url used
for the request to the APIC
208 returned: failure
or debug
210 sample: https://10.11.12.13/api/mo/uni/tn-production.json
213from ansible.module_utils.basic import AnsibleModule
214from ansible.module_utils.network.aci.aci import ACIModule, aci_argument_spec
216ACI_POOL_MAPPING = dict(
218 aci_class='fvnsVlanInstP',
219 aci_mo=
'infra/vlanns-',
222 aci_class=
'fvnsVxlanInstP',
223 aci_mo=
'infra/vxlanns-',
226 aci_class=
'fvnsVsanInstP',
227 aci_mo=
'infra/vsanns-',
234 argument_spec.update(
235 pool_type=dict(type=
'str', required=
True, aliases=[
'type'], choices=[
'vlan',
'vsan',
'vxlan']),
236 description=dict(type=
'str', aliases=[
'descr']),
237 pool=dict(type=
'str', aliases=[
'name',
'pool_name']),
238 pool_allocation_mode=dict(type=
'str', aliases=[
'allocation_mode',
'mode'], choices=[
'dynamic',
'static']),
239 state=dict(type=
'str', default=
'present', choices=[
'absent',
'present',
'query']),
243 argument_spec=argument_spec,
244 supports_check_mode=
True,
246 [
'state',
'absent', [
'pool']],
247 [
'state',
'present', [
'pool']],
251 description = module.params[
'description']
252 pool = module.params[
'pool']
253 pool_type = module.params[
'pool_type']
254 pool_allocation_mode = module.params[
'pool_allocation_mode']
255 state = module.params[
'state']
257 aci_class = ACI_POOL_MAPPING[pool_type][
'aci_class']
258 aci_mo = ACI_POOL_MAPPING[pool_type][
'aci_mo']
262 if pool_type !=
'vxlan' and pool
is not None:
263 if pool_allocation_mode
is not None:
264 pool_name =
'[{0}]-{1}'.
format(pool, pool_allocation_mode)
266 module.fail_json(msg=
"ACI requires parameter 'pool_allocation_mode' for 'pool_type' of 'vlan' and 'vsan' when parameter 'pool' is provided")
269 if pool_type ==
'vxlan' and pool_allocation_mode
is not None:
270 module.fail_json(msg=
"vxlan pools do not support setting the 'pool_allocation_mode'; please remove this parameter from the task")
276 aci_rn=
'{0}{1}'.
format(aci_mo, pool_name),
278 target_filter={
'name': pool},
284 if state ==
'present':
289 allocMode=pool_allocation_mode,
296 aci.get_diff(aci_class=aci_class)
301 elif state ==
'absent':
307if __name__ ==
"__main__":