8from __future__
import absolute_import, division, print_function
11ANSIBLE_METADATA = {
'metadata_version':
'1.1',
12 'status': [
'preview'],
13 'supported_by':
'certified'}
17module: aci_vlan_pool_encap_block
18short_description: Manage encap blocks assigned to VLAN pools (fvns:EncapBlk)
20- Manage VLAN encap blocks that are assigned to VLAN pools on Cisco ACI fabrics.
25 - The method used for allocating encaps to resources.
27 choices: [ dynamic, inherit, static]
31 - Description
for the pool encap block.
36 - The name of the pool that the encap block should be assigned to.
38 aliases: [ pool_name ]
41 - The method used
for allocating encaps to resources.
43 choices: [ dynamic, static]
44 aliases: [ pool_mode ]
47 - The end of encap block.
52 - The name to give to the encap block.
57 - The start of the encap block.
62 - Use C(present)
or C(absent)
for adding
or removing.
63 - Use C(query)
for listing an object
or multiple objects.
65 choices: [ absent, present, query ]
67extends_documentation_fragment: aci
69- The C(pool) must exist
in order to add
or delete a encap block.
71- module: aci_encap_pool_range
72- module: aci_vlan_pool
73- name: APIC Management Information Model reference
74 description: More information about the internal APIC
class B(fvns:EncapBlk).
75 link: https://developer.cisco.com/docs/apic-mim-ref/
77- Jacob McGill (
@jmcgill298)
78- Dag Wieers (
@dagwieers)
82- name: Add a new VLAN encap block
83 aci_vlan_pool_encap_block:
86 password: SomeSecretPassword
91 delegate_to: localhost
93- name: Remove a VLAN encap block
94 aci_vlan_pool_encap_block:
97 password: SomeSecretPassword
102 delegate_to: localhost
104- name: Query a VLAN encap block
105 aci_vlan_pool_encap_block:
108 password: SomeSecretPassword
113 delegate_to: localhost
114 register: query_result
116- name: Query a VLAN pool for encap blocks
117 aci_vlan_pool_encap_block:
120 password: SomeSecretPassword
123 delegate_to: localhost
124 register: query_result
126- name: Query all VLAN encap blocks
127 aci_vlan_pool_encap_block:
130 password: SomeSecretPassword
132 delegate_to: localhost
133 register: query_result
138 description: The existing configuration from the APIC after the module has finished
146 "descr":
"Production environment",
147 "dn":
"uni/tn-production",
148 "name":
"production",
157 description: The error information
as returned
from the APIC
163 "text":
"unknown managed object class foo"
166 description: The raw output returned by the APIC REST API (xml
or json)
167 returned: parse error
169 sample:
'<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
171 description: The actual/minimal configuration pushed to the APIC
178 "descr":
"Production environment"
183 description: The original configuration
from the APIC before the module has started
191 "descr":
"Production",
192 "dn":
"uni/tn-production",
193 "name":
"production",
202 description: The assembled configuration
from the user-provided parameters
209 "descr":
"Production environment",
215 description: The filter string used
for the request
216 returned: failure
or debug
218 sample: ?rsp-prop-include=config-only
220 description: The HTTP method used
for the request to the APIC
221 returned: failure
or debug
225 description: The HTTP response
from the APIC
226 returned: failure
or debug
228 sample: OK (30 bytes)
230 description: The HTTP status
from the APIC
231 returned: failure
or debug
235 description: The HTTP url used
for the request to the APIC
236 returned: failure
or debug
238 sample: https://10.11.12.13/api/mo/uni/tn-production.json
241from ansible.module_utils.basic import AnsibleModule
242from ansible.module_utils.network.aci.aci import ACIModule, aci_argument_spec
247 argument_spec.update(
248 pool=dict(type='str', aliases=[
'pool_name']),
249 block_name=dict(type=
'str', aliases=[
'name']),
250 block_end=dict(type=
'int', aliases=[
'end']),
251 block_start=dict(type=
'int', aliases=[
"start"]),
252 allocation_mode=dict(type=
'str', aliases=[
'mode'], choices=[
'dynamic',
'inherit',
'static']),
253 description=dict(type=
'str', aliases=[
'descr']),
254 pool_allocation_mode=dict(type=
'str', aliases=[
'pool_mode'], choices=[
'dynamic',
'static']),
255 state=dict(type=
'str', default=
'present', choices=[
'absent',
'present',
'query']),
259 argument_spec=argument_spec,
260 supports_check_mode=
True,
262 [
'state',
'absent', [
'pool',
'block_end',
'block_name',
'block_start']],
263 [
'state',
'present', [
'pool',
'block_end',
'block_name',
'block_start']],
267 allocation_mode = module.params[
'allocation_mode']
268 description = module.params[
'description']
269 pool = module.params[
'pool']
270 pool_allocation_mode = module.params[
'pool_allocation_mode']
271 block_end = module.params[
'block_end']
272 block_name = module.params[
'block_name']
273 block_start = module.params[
'block_start']
274 state = module.params[
'state']
276 if block_end
is not None:
277 encap_end =
'vlan-{0}'.
format(block_end)
281 if block_start
is not None:
282 encap_start =
'vlan-{0}'.
format(block_start)
287 aci_block_mo =
'from-[{0}]-to-[{1}]'.
format(encap_start, encap_end)
291 for encap_id
in block_end, block_start:
292 if encap_id
is not None:
293 if not 1 <= encap_id <= 4094:
294 module.fail_json(msg=
"vlan pools must have 'block_start' and 'block_end' values between 1 and 4094")
296 if block_end
is not None and block_start
is not None:
298 if block_start > block_end:
299 module.fail_json(msg=
"The 'block_start' must be less than or equal to the 'block_end'")
301 elif block_end
is None and block_start
is None:
302 if block_name
is None:
308 if pool_allocation_mode
is not None:
309 pool_name =
'[{0}]-{1}'.
format(pool, pool_allocation_mode)
311 module.fail_json(msg=
"ACI requires the 'pool_allocation_mode' when 'pool' is provided")
316 aci_class=
'fvnsVlanInstP',
317 aci_rn=
'infra/vlanns-{0}'.
format(pool_name),
319 target_filter={
'name': pool},
322 aci_class=
'fvnsEncapBlk',
324 module_object=aci_block_mo,
325 target_filter={
'from': encap_start,
'to': encap_end,
'name': block_name},
331 if state ==
'present':
333 aci_class=
'fvnsEncapBlk',
335 "allocMode": allocation_mode,
336 "descr": description,
343 aci.get_diff(aci_class=
'fvnsEncapBlk')
347 elif state ==
'absent':
353if __name__ ==
"__main__":