ansible  2.9.27
About: Ansible is an IT Configuration Management, Deployment \
About: Ansible (2.x) is an IT Configuration Management, Deployment & Orchestration tool.
ansible download page.
  Fossies Dox: ansible-2.9.27.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

aci_l3out.py
Go to the documentation of this file.
1#!/usr/bin/python
2# -*- coding: utf-8 -*-
3
4# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
5
6from __future__ import absolute_import, division, print_function
7__metaclass__ = type
8
9ANSIBLE_METADATA = {'metadata_version': '1.1',
10 'status': ['preview'],
11 'supported_by': 'certified'}
12
13DOCUMENTATION = r'''
14---
15module: aci_l3out
16short_description: Manage Layer 3 Outside (L3Out) objects (l3ext:Out)
17description:
18- Manage Layer 3 Outside (L3Out) on Cisco ACI fabrics.
19version_added: '2.6'
20options:
21 tenant:
22 description:
23 - Name of an existing tenant.
24 type: str
25 required: yes
26 aliases: [ tenant_name ]
27 l3out:
28 description:
29 - Name of L3Out being created.
30 type: str
31 required: yes
32 aliases: [ l3out_name, name ]
33 vrf:
34 description:
35 - Name of the VRF being associated with the L3Out.
36 type: str
37 required: yes
38 aliases: [ vrf_name ]
39 domain:
40 description:
41 - Name of the external L3 domain being associated with the L3Out.
42 type: str
43 required: yes
44 aliases: [ ext_routed_domain_name, routed_domain ]
45 dscp:
46 description:
47 - The target Differentiated Service (DSCP) value.
48 - The APIC defaults to C(unspecified) when unset during creation.
49 type: str
50 choices: [ AF11, AF12, AF13, AF21, AF22, AF23, AF31, AF32, AF33, AF41, AF42, AF43, CS0, CS1, CS2, CS3, CS4, CS5, CS6, CS7, EF, VA, unspecified ]
51 aliases: [ target ]
52 route_control:
53 description:
54 - Route Control enforcement direction. The only allowed values are export or import,export.
55 type: list
56 choices: [ export, import ]
57 aliases: [ route_control_enforcement ]
58 l3protocol:
59 description:
60 - Routing protocol for the L3Out
61 type: list
62 choices: [ bgp, eigrp, ospf, pim, static ]
63 asn:
64 description:
65 - The AS number for the L3Out.
66 - Only applicable when using 'eigrp' as the l3protocol
67 type: int
68 aliases: [ as_number ]
69 version_added: '2.8'
70 description:
71 description:
72 - Description for the L3Out.
73 type: str
74 aliases: [ descr ]
75 state:
76 description:
77 - Use C(present) or C(absent) for adding or removing.
78 - Use C(query) for listing an object or multiple objects.
79 type: str
80 choices: [ absent, present, query ]
81 default: present
82extends_documentation_fragment: aci
83notes:
84- The C(tenant) and C(domain) and C(vrf) used must exist before using this module in your playbook.
85 The M(aci_tenant) and M(aci_domain) and M(aci_vrf) modules can be used for this.
86seealso:
87- module: aci_tenant
88- module: aci_domain
89- module: aci_vrf
90- name: APIC Management Information Model reference
91 description: More information about the internal APIC class B(l3ext:Out).
92 link: https://developer.cisco.com/docs/apic-mim-ref/
93author:
94- Rostyslav Davydenko (@rost-d)
95'''
96
97EXAMPLES = r'''
98- name: Add a new L3Out
99 aci_l3out:
100 host: apic
101 username: admin
102 password: SomeSecretPassword
103 tenant: production
104 name: prod_l3out
105 description: L3Out for Production tenant
106 domain: l3dom_prod
107 vrf: prod
108 l3protocol: ospf
109 state: present
110 delegate_to: localhost
111
112- name: Delete L3Out
113 aci_l3out:
114 host: apic
115 username: admin
116 password: SomeSecretPassword
117 tenant: production
118 name: prod_l3out
119 state: absent
120 delegate_to: localhost
121
122- name: Query L3Out information
123 aci_l3out:
124 host: apic
125 username: admin
126 password: SomeSecretPassword
127 tenant: production
128 name: prod_l3out
129 state: query
130 delegate_to: localhost
131 register: query_result
132'''
133
134RETURN = r'''
135current:
136 description: The existing configuration from the APIC after the module has finished
137 returned: success
138 type: list
139 sample:
140 [
141 {
142 "fvTenant": {
143 "attributes": {
144 "descr": "Production environment",
145 "dn": "uni/tn-production",
146 "name": "production",
147 "nameAlias": "",
148 "ownerKey": "",
149 "ownerTag": ""
150 }
151 }
152 }
153 ]
154error:
155 description: The error information as returned from the APIC
156 returned: failure
157 type: dict
158 sample:
159 {
160 "code": "122",
161 "text": "unknown managed object class foo"
162 }
163raw:
164 description: The raw output returned by the APIC REST API (xml or json)
165 returned: parse error
166 type: str
167 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
168sent:
169 description: The actual/minimal configuration pushed to the APIC
170 returned: info
171 type: list
172 sample:
173 {
174 "fvTenant": {
175 "attributes": {
176 "descr": "Production environment"
177 }
178 }
179 }
180previous:
181 description: The original configuration from the APIC before the module has started
182 returned: info
183 type: list
184 sample:
185 [
186 {
187 "fvTenant": {
188 "attributes": {
189 "descr": "Production",
190 "dn": "uni/tn-production",
191 "name": "production",
192 "nameAlias": "",
193 "ownerKey": "",
194 "ownerTag": ""
195 }
196 }
197 }
198 ]
199proposed:
200 description: The assembled configuration from the user-provided parameters
201 returned: info
202 type: dict
203 sample:
204 {
205 "fvTenant": {
206 "attributes": {
207 "descr": "Production environment",
208 "name": "production"
209 }
210 }
211 }
212filter_string:
213 description: The filter string used for the request
214 returned: failure or debug
215 type: str
216 sample: ?rsp-prop-include=config-only
217method:
218 description: The HTTP method used for the request to the APIC
219 returned: failure or debug
220 type: str
221 sample: POST
222response:
223 description: The HTTP response from the APIC
224 returned: failure or debug
225 type: str
226 sample: OK (30 bytes)
227status:
228 description: The HTTP status from the APIC
229 returned: failure or debug
230 type: int
231 sample: 200
232url:
233 description: The HTTP url used for the request to the APIC
234 returned: failure or debug
235 type: str
236 sample: https://10.11.12.13/api/mo/uni/tn-production.json
237'''
238
239from ansible.module_utils.basic import AnsibleModule
240from ansible.module_utils.network.aci.aci import ACIModule, aci_argument_spec
241
242
243def main():
244 argument_spec = aci_argument_spec()
245 argument_spec.update(
246 tenant=dict(type='str', aliases=['tenant_name']), # Not required for querying all objects
247 l3out=dict(type='str', aliases=['l3out_name', 'name']), # Not required for querying all objects
248 domain=dict(type='str', aliases=['ext_routed_domain_name', 'routed_domain']),
249 vrf=dict(type='str', aliases=['vrf_name']),
250 description=dict(type='str', aliases=['descr']),
251 route_control=dict(type='list', choices=['export', 'import'], aliases=['route_control_enforcement']),
252 dscp=dict(type='str',
253 choices=['AF11', 'AF12', 'AF13', 'AF21', 'AF22', 'AF23', 'AF31', 'AF32', 'AF33', 'AF41', 'AF42',
254 'AF43', 'CS0', 'CS1', 'CS2', 'CS3', 'CS4', 'CS5', 'CS6', 'CS7', 'EF', 'VA', 'unspecified'],
255 aliases=['target']),
256 l3protocol=dict(type='list', choices=['bgp', 'eigrp', 'ospf', 'pim', 'static']),
257 asn=dict(type='int', aliases=['as_number']),
258 state=dict(type='str', default='present', choices=['absent', 'present', 'query'])
259 )
260
261 module = AnsibleModule(
262 argument_spec=argument_spec,
263 supports_check_mode=True,
264 required_if=[
265 ['state', 'absent', ['l3out', 'tenant']],
266 ['state', 'present', ['l3out', 'tenant', 'domain', 'vrf']],
267 ],
268 )
269
270 aci = ACIModule(module)
271
272 l3out = module.params['l3out']
273 domain = module.params['domain']
274 dscp = module.params['dscp']
275 description = module.params['description']
276 enforceRtctrl = module.params['route_control']
277 vrf = module.params['vrf']
278 l3protocol = module.params['l3protocol']
279 asn = module.params['asn']
280 state = module.params['state']
281 tenant = module.params['tenant']
282
283 if l3protocol:
284 if 'eigrp' in l3protocol and asn is None:
285 module.fail_json(msg="Parameter 'asn' is required when l3protocol is 'eigrp'")
286 if 'eigrp' not in l3protocol and asn is not None:
287 module.warn("Parameter 'asn' is only applicable when l3protocol is 'eigrp'. The ASN will be ignored")
288
289 enforce_ctrl = ''
290 if enforceRtctrl is not None:
291 if len(enforceRtctrl) == 1 and enforceRtctrl[0] == 'import':
292 aci.fail_json(
293 "The route_control parameter is invalid: allowed options are export or import,export only")
294 elif len(enforceRtctrl) == 1 and enforceRtctrl[0] == 'export':
295 enforce_ctrl = 'export'
296 else:
297 enforce_ctrl = 'export,import'
298 child_classes = ['l3extRsL3DomAtt', 'l3extRsEctx', 'bgpExtP', 'ospfExtP', 'eigrpExtP', 'pimExtP']
299
300 aci.construct_url(
301 root_class=dict(
302 aci_class='fvTenant',
303 aci_rn='tn-{0}'.format(tenant),
304 module_object=tenant,
305 target_filter={'name': tenant},
306 ),
307 subclass_1=dict(
308 aci_class='l3extOut',
309 aci_rn='out-{0}'.format(l3out),
310 module_object=l3out,
311 target_filter={'name': l3out},
312 ),
313 child_classes=child_classes,
314 )
315
316 aci.get_existing()
317
318 child_configs = [
319 dict(l3extRsL3DomAtt=dict(attributes=dict(
320 tDn='uni/l3dom-{0}'.format(domain)))),
321 dict(l3extRsEctx=dict(attributes=dict(tnFvCtxName=vrf))),
322 ]
323 if l3protocol is not None:
324 for protocol in l3protocol:
325 if protocol == 'bgp':
326 child_configs.append(
327 dict(bgpExtP=dict(attributes=dict(descr='', nameAlias=''))))
328 elif protocol == 'eigrp':
329 child_configs.append(
330 dict(eigrpExtP=dict(attributes=dict(descr='', nameAlias='', asn=asn))))
331 elif protocol == 'ospf':
332 child_configs.append(
333 dict(ospfExtP=dict(attributes=dict(descr='', nameAlias=''))))
334 elif protocol == 'pim':
335 child_configs.append(
336 dict(pimExtP=dict(attributes=dict(descr='', nameAlias=''))))
337
338 if state == 'present':
339 aci.payload(
340 aci_class='l3extOut',
341 class_config=dict(
342 name=l3out,
343 descr=description,
344 dn='uni/tn-{0}/out-{1}'.format(tenant, l3out),
345 enforceRtctrl=enforce_ctrl,
346 targetDscp=dscp
347 ),
348 child_configs=child_configs,
349 )
350
351 aci.get_diff(aci_class='l3extOut')
352
353 aci.post_config()
354
355 elif state == 'absent':
356 aci.delete_config()
357
358 aci.exit_json()
359
360
361if __name__ == "__main__":
362 main()