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_tenant.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_tenant
16short_description: Manage tenants (fv:Tenant)
17description:
18- Manage tenants on Cisco ACI fabrics.
19version_added: '2.4'
20options:
21 tenant:
22 description:
23 - The name of the tenant.
24 type: str
25 required: yes
26 aliases: [ name, tenant_name ]
27 description:
28 description:
29 - Description for the tenant.
30 type: str
31 aliases: [ descr ]
32 state:
33 description:
34 - Use C(present) or C(absent) for adding or removing.
35 - Use C(query) for listing an object or multiple objects.
36 type: str
37 choices: [ absent, present, query ]
38 default: present
39extends_documentation_fragment: aci
40seealso:
41- module: aci_ap
42- module: aci_bd
43- module: aci_contract
44- module: aci_filter
45- module: aci_vrf
46- name: APIC Management Information Model reference
47 description: More information about the internal APIC class B(fv:Tenant).
48 link: https://developer.cisco.com/docs/apic-mim-ref/
49author:
50- Jacob McGill (@jmcgill298)
51'''
52
53EXAMPLES = r'''
54- name: Add a new tenant
55 aci_tenant:
56 host: apic
57 username: admin
58 password: SomeSecretPassword
59 tenant: production
60 description: Production tenant
61 state: present
62 delegate_to: localhost
63
64- name: Remove a tenant
65 aci_tenant:
66 host: apic
67 username: admin
68 password: SomeSecretPassword
69 tenant: production
70 state: absent
71 delegate_to: localhost
72
73- name: Query a tenant
74 aci_tenant:
75 host: apic
76 username: admin
77 password: SomeSecretPassword
78 tenant: production
79 state: query
80 delegate_to: localhost
81 register: query_result
82
83- name: Query all tenants
84 aci_tenant:
85 host: apic
86 username: admin
87 password: SomeSecretPassword
88 state: query
89 delegate_to: localhost
90 register: query_result
91'''
92
93RETURN = r'''
94current:
95 description: The existing configuration from the APIC after the module has finished
96 returned: success
97 type: list
98 sample:
99 [
100 {
101 "fvTenant": {
102 "attributes": {
103 "descr": "Production environment",
104 "dn": "uni/tn-production",
105 "name": "production",
106 "nameAlias": "",
107 "ownerKey": "",
108 "ownerTag": ""
109 }
110 }
111 }
112 ]
113error:
114 description: The error information as returned from the APIC
115 returned: failure
116 type: dict
117 sample:
118 {
119 "code": "122",
120 "text": "unknown managed object class foo"
121 }
122raw:
123 description: The raw output returned by the APIC REST API (xml or json)
124 returned: parse error
125 type: str
126 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
127sent:
128 description: The actual/minimal configuration pushed to the APIC
129 returned: info
130 type: list
131 sample:
132 {
133 "fvTenant": {
134 "attributes": {
135 "descr": "Production environment"
136 }
137 }
138 }
139previous:
140 description: The original configuration from the APIC before the module has started
141 returned: info
142 type: list
143 sample:
144 [
145 {
146 "fvTenant": {
147 "attributes": {
148 "descr": "Production",
149 "dn": "uni/tn-production",
150 "name": "production",
151 "nameAlias": "",
152 "ownerKey": "",
153 "ownerTag": ""
154 }
155 }
156 }
157 ]
158proposed:
159 description: The assembled configuration from the user-provided parameters
160 returned: info
161 type: dict
162 sample:
163 {
164 "fvTenant": {
165 "attributes": {
166 "descr": "Production environment",
167 "name": "production"
168 }
169 }
170 }
171filter_string:
172 description: The filter string used for the request
173 returned: failure or debug
174 type: str
175 sample: ?rsp-prop-include=config-only
176method:
177 description: The HTTP method used for the request to the APIC
178 returned: failure or debug
179 type: str
180 sample: POST
181response:
182 description: The HTTP response from the APIC
183 returned: failure or debug
184 type: str
185 sample: OK (30 bytes)
186status:
187 description: The HTTP status from the APIC
188 returned: failure or debug
189 type: int
190 sample: 200
191url:
192 description: The HTTP url used for the request to the APIC
193 returned: failure or debug
194 type: str
195 sample: https://10.11.12.13/api/mo/uni/tn-production.json
196'''
197
198from ansible.module_utils.basic import AnsibleModule
199from ansible.module_utils.network.aci.aci import ACIModule, aci_argument_spec
200
201
202def main():
203 argument_spec = aci_argument_spec()
204 argument_spec.update(
205 tenant=dict(type='str', aliases=['name', 'tenant_name']), # Not required for querying all objects
206 description=dict(type='str', aliases=['descr']),
207 state=dict(type='str', default='present', choices=['absent', 'present', 'query']),
208 )
209
210 module = AnsibleModule(
211 argument_spec=argument_spec,
212 supports_check_mode=True,
213 required_if=[
214 ['state', 'absent', ['tenant']],
215 ['state', 'present', ['tenant']],
216 ],
217 )
218
219 description = module.params['description']
220 state = module.params['state']
221 tenant = module.params['tenant']
222
223 aci = ACIModule(module)
224 aci.construct_url(
225 root_class=dict(
226 aci_class='fvTenant',
227 aci_rn='tn-{0}'.format(tenant),
228 module_object=tenant,
229 target_filter={'name': tenant},
230 ),
231 )
232 aci.get_existing()
233
234 if state == 'present':
235 aci.payload(
236 aci_class='fvTenant',
237 class_config=dict(
238 name=tenant,
239 descr=description,
240 ),
241 )
242
243 aci.get_diff(aci_class='fvTenant')
244
245 aci.post_config()
246
247 elif state == 'absent':
248 aci.delete_config()
249
250 aci.exit_json()
251
252
253if __name__ == "__main__":
254 main()