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_vmm_credential.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': 'community'}
12
13DOCUMENTATION = r'''
14---
15module: aci_vmm_credential
16short_description: Manage virtual domain credential profiles (vmm:UsrAccP)
17description:
18- Manage virtual domain credential profiles on Cisco ACI fabrics.
19version_added: '2.9'
20options:
21 name:
22 description:
23 - Name of the credential profile.
24 type: str
25 aliases: [ credential_name, credential_profile ]
26 credential_password:
27 description:
28 - VMM controller password.
29 type: str
30 aliases: []
31 credential_username:
32 description:
33 - VMM controller username.
34 type: str
35 aliases: []
36 description:
37 description:
38 - Description for the tenant.
39 type: str
40 aliases: [ descr ]
41 domain:
42 description:
43 - Name of the virtual domain profile.
44 type: str
45 aliases: [ domain_name, domain_profile, name ]
46 state:
47 description:
48 - Use C(present) or C(absent) for adding or removing.
49 - Use C(query) for listing an object or multiple objects.
50 type: str
51 choices: [ absent, present, query ]
52 default: present
53 vm_provider:
54 description:
55 - The VM platform for VMM Domains.
56 - Support for Kubernetes was added in ACI v3.0.
57 - Support for CloudFoundry, OpenShift and Red Hat was added in ACI v3.1.
58 type: str
59 choices: [ cloudfoundry, kubernetes, microsoft, openshift, openstack, redhat, vmware ]
60extends_documentation_fragment: aci
61seealso:
62- module: aci_domain
63- name: APIC Management Information Model reference
64 description: More information about the internal APIC classes B(vmm:DomP)
65 link: https://developer.cisco.com/docs/apic-mim-ref/
66author:
67- Jason Juenger (@jasonjuenger)
68'''
69
70EXAMPLES = r'''
71- name: Add credential to VMware VMM domain
72 aci_vmm_credential:
73 host: apic
74 username: admin
75 password: SomeSecretPassword
76 domain: vmware_dom
77 description: secure credential
78 name: vCenterCredential
79 credential_username: vCenterUsername
80 credential_password: vCenterPassword
81 vm_provider: vmware
82 state: present
83
84- name: Remove credential from VMware VMM domain
85 aci_vmm_credential:
86 host: apic
87 username: admin
88 password: SomeSecretPassword
89 domain: vmware_dom
90 name: myCredential
91 vm_provider: vmware
92 state: absent
93
94- name: Query a specific VMware VMM credential
95 aci_vmm_credential:
96 host: apic
97 username: admin
98 password: SomeSecretPassword
99 domain: vmware_dom
100 name: vCenterCredential
101 vm_provider: vmware
102 state: query
103 delegate_to: localhost
104 register: query_result
105
106- name: Query all VMware VMM credentials
107 aci_vmm_credential:
108 host: apic
109 username: admin
110 password: SomeSecretPassword
111 domain: vmware_dom
112 vm_provider: vmware
113 state: query
114 delegate_to: localhost
115 register: query_result
116'''
117
118RETURN = r'''
119current:
120 description: The existing configuration from the APIC after the module has finished
121 returned: success
122 type: list
123 sample:
124 [
125 {
126 "fvTenant": {
127 "attributes": {
128 "descr": "Production environment",
129 "dn": "uni/tn-production",
130 "name": "production",
131 "nameAlias": "",
132 "ownerKey": "",
133 "ownerTag": ""
134 }
135 }
136 }
137 ]
138error:
139 description: The error information as returned from the APIC
140 returned: failure
141 type: dict
142 sample:
143 {
144 "code": "122",
145 "text": "unknown managed object class foo"
146 }
147raw:
148 description: The raw output returned by the APIC REST API (xml or json)
149 returned: parse error
150 type: str
151 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
152sent:
153 description: The actual/minimal configuration pushed to the APIC
154 returned: info
155 type: list
156 sample:
157 {
158 "fvTenant": {
159 "attributes": {
160 "descr": "Production environment"
161 }
162 }
163 }
164previous:
165 description: The original configuration from the APIC before the module has started
166 returned: info
167 type: list
168 sample:
169 [
170 {
171 "fvTenant": {
172 "attributes": {
173 "descr": "Production",
174 "dn": "uni/tn-production",
175 "name": "production",
176 "nameAlias": "",
177 "ownerKey": "",
178 "ownerTag": ""
179 }
180 }
181 }
182 ]
183proposed:
184 description: The assembled configuration from the user-provided parameters
185 returned: info
186 type: dict
187 sample:
188 {
189 "fvTenant": {
190 "attributes": {
191 "descr": "Production environment",
192 "name": "production"
193 }
194 }
195 }
196filter_string:
197 description: The filter string used for the request
198 returned: failure or debug
199 type: str
200 sample: ?rsp-prop-include=config-only
201method:
202 description: The HTTP method used for the request to the APIC
203 returned: failure or debug
204 type: str
205 sample: POST
206response:
207 description: The HTTP response from the APIC
208 returned: failure or debug
209 type: str
210 sample: OK (30 bytes)
211status:
212 description: The HTTP status from the APIC
213 returned: failure or debug
214 type: int
215 sample: 200
216url:
217 description: The HTTP url used for the request to the APIC
218 returned: failure or debug
219 type: str
220 sample: https://10.11.12.13/api/mo/uni/tn-production.json
221'''
222
223from ansible.module_utils.basic import AnsibleModule
224from ansible.module_utils.network.aci.aci import ACIModule, aci_argument_spec
225
226VM_PROVIDER_MAPPING = dict(
227 cloudfoundry='CloudFoundry',
228 kubernetes='Kubernetes',
229 microsoft='Microsoft',
230 openshift='OpenShift',
231 openstack='OpenStack',
232 redhat='Redhat',
233 vmware='VMware',
234)
235
236
237def main():
238 argument_spec = aci_argument_spec()
239 argument_spec.update(
240 name=dict(type='str', aliases=['credential_name', 'credential_profile']),
241 credential_password=dict(type='str'),
242 credential_username=dict(type='str'),
243 description=dict(type='str', aliases=['descr']),
244 domain=dict(type='str', aliases=['domain_name', 'domain_profile']),
245 state=dict(type='str', default='present', choices=['absent', 'present', 'query']),
246 vm_provider=dict(type='str', choices=VM_PROVIDER_MAPPING.keys())
247 )
248
249 module = AnsibleModule(
250 argument_spec=argument_spec,
251 supports_check_mode=True,
252 required_if=[
253 ['state', 'absent', ['domain']],
254 ['state', 'present', ['domain']],
255 ],
256 )
257
258 name = module.params['name']
259 credential_password = module.params['credential_password']
260 credential_username = module.params['credential_username']
261 description = module.params['description']
262 domain = module.params['domain']
263 state = module.params['state']
264 vm_provider = module.params['vm_provider']
265
266 credential_class = 'vmmUsrAccP'
267 usracc_mo = 'uni/vmmp-{0}/dom-{1}/usracc-{2}'.format(VM_PROVIDER_MAPPING[vm_provider], domain, name)
268 usracc_rn = 'vmmp-{0}/dom-{1}/usracc-{2}'.format(VM_PROVIDER_MAPPING[vm_provider], domain, name)
269
270 # Ensure that querying all objects works when only domain is provided
271 if name is None:
272 usracc_mo = None
273
274 aci = ACIModule(module)
275 aci.construct_url(
276 root_class=dict(
277 aci_class=credential_class,
278 aci_rn=usracc_rn,
279 module_object=usracc_mo,
280 target_filter={'name': domain, 'usracc': name},
281 ),
282 )
283
284 aci.get_existing()
285
286 if state == 'present':
287 aci.payload(
288 aci_class=credential_class,
289 class_config=dict(
290 descr=description,
291 name=name,
292 pwd=credential_password,
293 usr=credential_username
294 ),
295 )
296
297 aci.get_diff(aci_class=credential_class)
298
299 aci.post_config()
300
301 elif state == 'absent':
302 aci.delete_config()
303
304 aci.exit_json()
305
306
307if __name__ == "__main__":
308 main()