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_extsubnet.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_extsubnet
16short_description: Manage External Subnet objects (l3extSubnet:extsubnet)
17description:
18- Manage External Subnet objects (l3extSubnet:extsubnet)
19version_added: '2.9'
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 an existing L3Out.
30 type: str
31 required: yes
32 aliases: [ l3out_name ]
33 extepg:
34 description:
35 - Name of an existing ExtEpg.
36 type: str
37 required: yes
38 aliases: [ extepg_name ]
39 network:
40 description:
41 - The network address for the Subnet.
42 type: str
43 required: yes
44 aliases: [ address, ip ]
45 subnet_name:
46 description:
47 - Name of External Subnet being created.
48 type: str
49 aliases: [ name ]
50 description:
51 description:
52 - Description for the External Subnet.
53 type: str
54 aliases: [ descr ]
55 scope:
56 description:
57 - Determines the scope of the Subnet.
58 - The C(export-rtctrl) option controls which external networks are advertised out of the fabric using route-maps and IP prefix-lists.
59 - The C(import-security) option classifies for the external EPG.
60 The rules and contracts defined in this external EPG apply to networks matching this subnet.
61 - The C(shared-rtctrl) option controls which external prefixes are advertised to other tenants for shared services.
62 - The C(shared-security) option configures the classifier for the subnets in the VRF where the routes are leaked.
63 - The APIC defaults to C(import-security) when unset during creation.
64 type: list
65 choices: [ export-rtctrl, import-security, shared-rtctrl, shared-security ]
66 state:
67 description:
68 - Use C(present) or C(absent) for adding or removing.
69 - Use C(query) for listing an object or multiple objects.
70 type: str
71 choices: [ absent, present, query ]
72 default: present
73extends_documentation_fragment: aci
74notes:
75- The C(tenant) and C(domain) and C(vrf) used must exist before using this module in your playbook.
76 The M(aci_tenant) and M(aci_domain) and M(aci_vrf) modules can be used for this.
77seealso:
78- module: aci_tenant
79- module: aci_domain
80- module: aci_vrf
81- name: APIC Management Information Model reference
82 description: More information about the internal APIC class B(l3ext:Out).
83 link: https://developer.cisco.com/docs/apic-mim-ref/
84author:
85- Rostyslav Davydenko (@rost-d)
86'''
87
88EXAMPLES = r'''
89- name: Add a new External Subnet
90 aci_l3out_extsubnet:
91 host: apic
92 username: admin
93 password: SomeSecretPassword
94 tenant: production
95 l3out: prod_l3out
96 extepg: prod_extepg
97 description: External Subnet for Production ExtEpg
98 network: 192.0.2.0/24
99 scope: export-rtctrl
100 state: present
101 delegate_to: localhost
102
103- name: Delete External Subnet
104 aci_l3out_extsubnet:
105 host: apic
106 username: admin
107 password: SomeSecretPassword
108 tenant: production
109 l3out: prod_l3out
110 extepg: prod_extepg
111 network: 192.0.2.0/24
112 state: absent
113 delegate_to: localhost
114
115- name: Query ExtEpg information
116 aci_l3out_extsubnet:
117 host: apic
118 username: admin
119 password: SomeSecretPassword
120 tenant: production
121 l3out: prod_l3out
122 extepg: prod_extepg
123 network: 192.0.2.0/24
124 state: query
125 delegate_to: localhost
126 register: query_result
127'''
128
129RETURN = r'''
130current:
131 description: The existing configuration from the APIC after the module has finished
132 returned: success
133 type: list
134 sample:
135 [
136 {
137 "fvTenant": {
138 "attributes": {
139 "descr": "Production environment",
140 "dn": "uni/tn-production",
141 "name": "production",
142 "nameAlias": "",
143 "ownerKey": "",
144 "ownerTag": ""
145 }
146 }
147 }
148 ]
149error:
150 description: The error information as returned from the APIC
151 returned: failure
152 type: dict
153 sample:
154 {
155 "code": "122",
156 "text": "unknown managed object class foo"
157 }
158raw:
159 description: The raw output returned by the APIC REST API (xml or json)
160 returned: parse error
161 type: str
162 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
163sent:
164 description: The actual/minimal configuration pushed to the APIC
165 returned: info
166 type: list
167 sample:
168 {
169 "fvTenant": {
170 "attributes": {
171 "descr": "Production environment"
172 }
173 }
174 }
175previous:
176 description: The original configuration from the APIC before the module has started
177 returned: info
178 type: list
179 sample:
180 [
181 {
182 "fvTenant": {
183 "attributes": {
184 "descr": "Production",
185 "dn": "uni/tn-production",
186 "name": "production",
187 "nameAlias": "",
188 "ownerKey": "",
189 "ownerTag": ""
190 }
191 }
192 }
193 ]
194proposed:
195 description: The assembled configuration from the user-provided parameters
196 returned: info
197 type: dict
198 sample:
199 {
200 "fvTenant": {
201 "attributes": {
202 "descr": "Production environment",
203 "name": "production"
204 }
205 }
206 }
207filter_string:
208 description: The filter string used for the request
209 returned: failure or debug
210 type: str
211 sample: ?rsp-prop-include=config-only
212method:
213 description: The HTTP method used for the request to the APIC
214 returned: failure or debug
215 type: str
216 sample: POST
217response:
218 description: The HTTP response from the APIC
219 returned: failure or debug
220 type: str
221 sample: OK (30 bytes)
222status:
223 description: The HTTP status from the APIC
224 returned: failure or debug
225 type: int
226 sample: 200
227url:
228 description: The HTTP url used for the request to the APIC
229 returned: failure or debug
230 type: str
231 sample: https://10.11.12.13/api/mo/uni/tn-production.json
232'''
233
234from ansible.module_utils.basic import AnsibleModule
235from ansible.module_utils.network.aci.aci import ACIModule, aci_argument_spec
236
237
238def main():
239 argument_spec = aci_argument_spec()
240 argument_spec.update(
241 tenant=dict(type='str', aliases=['tenant_name']), # Not required for querying all objects
242 l3out=dict(type='str', aliases=['l3out_name']), # Not required for querying all objects
243 extepg=dict(type='str', aliases=['extepg_name', 'name']), # Not required for querying all objects
244 network=dict(type='str', aliases=['address', 'ip']),
245 description=dict(type='str', aliases=['descr']),
246 subnet_name=dict(type='str', aliases=['name']),
247 scope=dict(type='list', choices=['export-rtctrl', 'import-security', 'shared-rtctrl', 'shared-security']),
248 state=dict(type='str', default='present', choices=['absent', 'present', 'query'])
249 )
250
251 module = AnsibleModule(
252 argument_spec=argument_spec,
253 supports_check_mode=True,
254 required_if=[
255 ['state', 'present', ['network']],
256 ['state', 'absent', ['network']],
257 ],
258 )
259
260 aci = ACIModule(module)
261
262 tenant = module.params['tenant']
263 l3out = module.params['l3out']
264 extepg = module.params['extepg']
265 network = module.params['network']
266 description = module.params['description']
267 subnet_name = module.params['subnet_name']
268 scope = ','.join(sorted(module.params['scope']))
269 state = module.params['state']
270
271 aci.construct_url(
272 root_class=dict(
273 aci_class='fvTenant',
274 aci_rn='tn-{0}'.format(tenant),
275 module_object=tenant,
276 target_filter={'name': tenant},
277 ),
278 subclass_1=dict(
279 aci_class='l3extOut',
280 aci_rn='out-{0}'.format(l3out),
281 module_object=l3out,
282 target_filter={'name': l3out},
283 ),
284 subclass_2=dict(
285 aci_class='l3extInstP',
286 aci_rn='instP-{0}'.format(extepg),
287 module_object=extepg,
288 target_filter={'name': extepg},
289 ),
290 subclass_3=dict(
291 aci_class='l3extSubnet',
292 aci_rn='extsubnet-[{0}]'.format(network),
293 module_object=network,
294 target_filter={'name': network},
295 ),
296 )
297
298 aci.get_existing()
299
300 if state == 'present':
301 aci.payload(
302 aci_class='l3extSubnet',
303 class_config=dict(
304 ip=network,
305 descr=description,
306 name=subnet_name,
307 scope=scope,
308 ),
309 )
310
311 aci.get_diff(aci_class='l3extSubnet')
312
313 aci.post_config()
314
315 elif state == 'absent':
316 aci.delete_config()
317
318 aci.exit_json()
319
320
321if __name__ == "__main__":
322 main()