Debian Codegraph @

ansible_collections/f5networks/f5_modules/plugins/modules/bigip_device_auth_ldap.py

raw symbols SCIP
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3 #
4 # Copyright: (c) 2018, F5 Networks Inc.
5 # GNU General Public License v3.0 (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
6
7 from __future__ import absolute_import, division, print_function
8
9 __metaclass__ = type
10
11 DOCUMENTATION = r'''
12 ---
13 module: bigip_device_auth_ldap
14 short_description: Manage LDAP device authentication settings on BIG-IP
15 description:
16 - Manage LDAP device authentication settings on BIG-IP.
17 version_added: "1.0.0"
18 options:
19 servers:
20 description:
21 - Specifies the LDAP servers the system must use to obtain
22 authentication information. You must specify a server when you
23 create an LDAP configuration object.
24 type: list
25 elements: str
26 port:
27 description:
28 - Specifies the port the system uses for access to the remote host server.
29 - When configuring LDAP device authentication for the first time, the default
30 port is C(389) if this parameter is not specified.
31 type: int
32 remote_directory_tree:
33 description:
34 - Specifies the file location (tree) of the user authentication database on the
35 server.
36 type: str
37 scope:
38 description:
39 - Specifies the level of the remote Active Directory or LDAP directory the
40 system should search for the user authentication.
41 type: str
42 choices:
43 - sub
44 - one
45 - base
46 bind_dn:
47 description:
48 - Specifies the distinguished name for the Active Directory or LDAP server user
49 ID.
50 - The BIG-IP client authentication module does not support Active Directory or
51 LDAP servers that do not perform bind referral when authenticating referred
52 accounts.
53 - Therefore, if you plan to use Active Directory or LDAP as your authentication
54 source and want to use referred accounts, make sure your servers perform bind
55 referral.
56 type: str
57 bind_password:
58 description:
59 - Specifies a password for the Active Directory or LDAP server user ID.
60 type: str
61 user_template:
62 description:
63 - Specifies the distinguished name of the user who is logging on.
64 - You specify the template as a variable that the system replaces with user-specific
65 information during the logon attempt.
66 - For example, you could specify a user template such as C(%[email protected]) or
67 C(uxml:id=%s,ou=people,dc=siterequest,dc=com).
68 - When a user attempts to log on, the system replaces C(%s) with the name the user
69 specified in the Basic Authentication dialog box, and passes that as the
70 distinguished name for the bind operation.
71 - The system passes the associated password as the password for the bind operation.
72 - This field can contain only one C(%s) and cannot contain any other format
73 specifiers.
74 type: str
75 check_member_attr:
76 description:
77 - Checks the member attribute of the user in the remote LDAP or AD group.
78 type: bool
79 ssl:
80 description:
81 - Specifies whether the system uses an SSL port to communicate with the LDAP server.
82 type: str
83 choices:
84 - "yes"
85 - "no"
86 - start-tls
87 ca_cert:
88 description:
89 - Specifies the name of an SSL certificate from a certificate authority (CA).
90 - To remove this value, use the reserved value C(none).
91 type: str
92 aliases: [ ssl_ca_cert ]
93 client_key:
94 description:
95 - Specifies the name of an SSL client key.
96 - To remove this value, use the reserved value C(none).
97 type: str
98 aliases: [ ssl_client_key ]
99 client_cert:
100 description:
101 - Specifies the name of an SSL client certificate.
102 - To remove this value, use the reserved value C(none).
103 type: str
104 aliases: [ ssl_client_cert ]
105 validate_certs:
106 description:
107 - Specifies whether the system checks an SSL peer, as a result of which the
108 system requires and verifies the server certificate.
109 type: bool
110 aliases: [ ssl_check_peer ]
111 login_ldap_attr:
112 description:
113 - Specifies the LDAP directory attribute containing the local user name that is
114 associated with the selected directory entry.
115 - If this parameter is not specified, when configuring LDAP device authentication for the first time,
116 the default port is C(samaccountname).
117 type: str
118 fallback_to_local:
119 description:
120 - Specifies the system uses the Local authentication method if the remote
121 authentication method is not available.
122 - Option only available on C(TMOS 13.0.0) and above.
123 type: bool
124 referrals:
125 description:
126 - Specifies whether automatic referral chasing should be enabled.
127 - Option only available on C(TMOS 15.1.0) and above.
128 type: bool
129 version_added: "1.22.0"
130 state:
131 description:
132 - When C(present), ensures the device authentication method exists.
133 - When C(absent), ensures the device authentication method does not exist.
134 - When C(state) equal to (absent), before you can delete the LDAP configuration, the system must set auth to
135 some alternative. The system ships with a system auth called C(local), therefore the system authentication type
136 is set to that value on the device upon removal of LDAP configuration.
137 type: str
138 choices:
139 - present
140 - absent
141 default: present
142 update_password:
143 description:
144 - C(always) always updates the C(bind_password).
145 - C(on_create) only sets the C(bind_password) for newly created authentication
146 mechanisms.
147 type: str
148 choices:
149 - always
150 - on_create
151 default: always
152 use_for_auth:
153 description:
154 - Specifies whether or not this auth source is put in use on the system.
155 - If C(true), the module sets the current system auth type to the value of C(ldap).
156 - If C(false), the module sets the authentication type to C(local), similar behavior to when C(state) is C(absent),
157 without removing the configured LDAP resource.
158 type: bool
159 source_type:
160 description:
161 - Specifies the auth source for user authentication, should be used with C(use_for_auth).
162 type: str
163 choices:
164 - ldap
165 - active-directory
166 default: ldap
167 version_added: "1.13.0"
168 extends_documentation_fragment: f5networks.f5_modules.f5
169 author:
170 - Tim Rupp (@caphrim007)
171 - Wojciech Wypior (@wojtek0806)
172 '''
173
174 EXAMPLES = r'''
175 - name: Create an LDAP authentication object
176 bigip_device_auth_ldap:
177 name: foo
178 provider:
179 password: secret
180 server: lb.mydomain.com
181 user: admin
182 delegate_to: localhost
183 '''
184
185 RETURN = r'''
186 servers:
187 description: LDAP servers used by the system to obtain authentication information.
188 returned: changed
189 type: list
190 sample: ['192.168.1.1', '192.168.1.2']
191 port:
192 description: The port the system uses for access to the remote LDAP server.
193 returned: changed
194 type: int
195 sample: 389
196 remote_directory_tree:
197 description: File location (tree) of the user authentication database on the server.
198 returned: changed
199 type: str
200 sample: "CN=Users,DC=FOOBAR,DC=LOCAL"
201 scope:
202 description: The level of the remote Active Directory or LDAP directory searched for user authentication.
203 returned: changed
204 type: str
205 sample: base
206 bind_dn:
207 description: The distinguished name for the Active Directory or LDAP server user ID.
208 returned: changed
209 type: str
210 sample: "[email protected]"
211 user_template:
212 description: The distinguished name of the user who is logging on.
213 returned: changed
214 type: str
215 sample: "uid=%s,ou=people,dc=foobar,dc=local"
216 check_member_attr:
217 description: The user's member attribute in the remote LDAP or AD group.
218 returned: changed
219 type: bool
220 sample: true
221 ssl:
222 description: Specifies whether the system uses an SSL port to communicate with the LDAP server.
223 returned: changed
224 type: str
225 sample: start-tls
226 ca_cert:
227 description: The name of an SSL certificate from a certificate authority.
228 returned: changed
229 type: str
230 sample: My-Trusted-CA-Bundle.crt
231 client_key:
232 description: The name of an SSL client key.
233 returned: changed
234 type: str
235 sample: MyKey.key
236 client_cert:
237 description: The name of an SSL client certificate.
238 returned: changed
239 type: str
240 sample: MyCert.crt
241 validate_certs:
242 description: Indicates if the system checks an SSL peer.
243 returned: changed
244 type: bool
245 sample: true
246 login_ldap_attr:
247 description: The LDAP directory attribute containing the local user name associated with the selected directory entry.
248 returned: changed
249 type: str
250 sample: samaccountname
251 fallback_to_local:
252 description: Specifies the system uses the Local authentication method as fallback
253 returned: changed
254 type: bool
255 sample: true
256 referrals:
257 description: Specifies whether automatic referral chasing should be enabled
258 returned: changed
259 type: bool
260 sample: true
261 '''
262
263 from datetime import datetime
264 from ansible.module_utils.basic import AnsibleModule
265
266 from ..module_utils.bigip import F5RestClient
267 from ..module_utils.common import (
268 F5ModuleError, AnsibleF5Parameters, transform_name, f5_argument_spec, flatten_boolean, fq_name
269 )
270 from ..module_utils.compare import cmp_str_with_none
271 from ..module_utils.icontrol import tmos_version
272 from ..module_utils.teem import send_teem
273
274
275 class Parameters(AnsibleF5Parameters):
276 api_map = {
277 'bindDn': 'bind_dn',
278 'bindPw': 'bind_password',
279 'userTemplate': 'user_template',
280 'fallback': 'fallback_to_local',
281 'referrals': 'referrals',
282 'loginAttribute': 'login_ldap_attr',
283 'sslCheckPeer': 'validate_certs',
284 'sslClientCert': 'client_cert',
285 'sslClientKey': 'client_key',
286 'sslCaCertFile': 'ca_cert',
287 'checkRolesGroup': 'check_member_attr',
288 'searchBaseDn': 'remote_directory_tree',
289 }
290
291 api_attributes = [
292 'bindDn',
293 'bindPw',
294 'checkRolesGroup',
295 'loginAttribute',
296 'port',
297 'scope',
298 'searchBaseDn',
299 'servers',
300 'ssl',
301 'sslCaCertFile',
302 'sslCheckPeer',
303 'sslClientCert',
304 'sslClientKey',
305 'userTemplate',
306 'referrals',
307 ]
308
309 returnables = [
310 'bind_dn',
311 'bind_password',
312 'check_member_attr',
313 'fallback_to_local',
314 'referrals',
315 'login_ldap_attr',
316 'port',
317 'remote_directory_tree',
318 'scope',
319 'servers',
320 'ssl',
321 'ca_cert',
322 'validate_certs',
323 'client_cert',
324 'client_key',
325 'user_template',
326 ]
327
328 updatables = [
329 'bind_dn',
330 'bind_password',
331 'check_member_attr',
332 'fallback_to_local',
333 'referrals',
334 'login_ldap_attr',
335 'port',
336 'remote_directory_tree',
337 'scope',
338 'servers',
339 'ssl',
340 'ca_cert',
341 'validate_certs',
342 'client_cert',
343 'client_key',
344 'user_template',
345 'auth_source',
346 ]
347
348 @property
349 def ca_cert(self):
350 if self._values['ca_cert'] is None:
351 return None
352 elif self._values['ca_cert'] in ['none', '']:
353 return ''
354 return fq_name(self.partition, self._values['ca_cert'])
355
356 @property
357 def client_key(self):
358 if self._values['client_key'] is None:
359 return None
360 elif self._values['client_key'] in ['none', '']:
361 return ''
362 return fq_name(self.partition, self._values['client_key'])
363
364 @property
365 def client_cert(self):
366 if self._values['client_cert'] is None:
367 return None
368 elif self._values['client_cert'] in ['none', '']:
369 return ''
370 return fq_name(self.partition, self._values['client_cert'])
371
372 @property
373 def validate_certs(self):
374 return flatten_boolean(self._values['validate_certs'])
375
376 @property
377 def check_member_attr(self):
378 return flatten_boolean(self._values['check_member_attr'])
379
380 @property
381 def login_ldap_attr(self):
382 if self._values['login_ldap_attr'] is None:
383 return None
384 elif self._values['login_ldap_attr'] in ['none', '']:
385 return ''
386 return self._values['login_ldap_attr']
387
388 @property
389 def user_template(self):
390 if self._values['user_template'] is None:
391 return None
392 elif self._values['user_template'] in ['none', '']:
393 return ''
394 return self._values['user_template']
395
396 @property
397 def ssl(self):
398 if self._values['ssl'] is None:
399 return None
400 elif self._values['ssl'] == 'start-tls':
401 return 'start-tls'
402 return flatten_boolean(self._values['ssl'])
403
404 @property
405 def fallback_to_local(self):
406 return flatten_boolean(self._values['fallback_to_local'])
407
408 @property
409 def referrals(self):
410 return flatten_boolean(self._values['referrals'])
411
412
413 class ApiParameters(Parameters):
414 pass
415
416
417 class ModuleParameters(Parameters):
418 @property
419 def use_for_auth(self):
420 return flatten_boolean(self._values['use_for_auth'])
421
422 @property
423 def auth_source(self):
424 if self._values['use_for_auth'] is None:
425 return None
426 if self.use_for_auth == 'yes':
427 return self._values['source_type']
428 if self.use_for_auth == 'no':
429 return 'local'
430
431
432 class Changes(Parameters):
433 def to_return(self):
434 result = {}
435 try:
436 for returnable in self.returnables:
437 result[returnable] = getattr(self, returnable)
438 result = self._filter_params(result)
439 except Exception:
440 raise
441 return result
442
443
444 class UsableChanges(Changes):
445 @property
446 def validate_certs(self):
447 if self._values['validate_certs'] is None:
448 return None
449 elif self._values['validate_certs'] == 'yes':
450 return 'enabled'
451 return 'disabled'
452
453 @property
454 def fallback_to_local(self):
455 if self._values['fallback_to_local'] is None:
456 return None
457 elif self._values['fallback_to_local'] == 'yes':
458 return 'true'
459 return 'false'
460
461 @property
462 def referrals(self):
463 if self._values['referrals'] is None:
464 return None
465 elif self._values['referrals'] == 'yes':
466 return 'yes'
467 return 'no'
468
469 @property
470 def check_member_attr(self):
471 if self._values['check_member_attr'] is None:
472 return None
473 elif self._values['check_member_attr'] == 'yes':
474 return 'enabled'
475 return 'disabled'
476
477 @property
478 def ssl(self):
479 if self._values['ssl'] is None:
480 return None
481 elif self._values['ssl'] == 'start-tls':
482 return 'start-tls'
483 elif self._values['ssl'] == 'yes':
484 return 'enabled'
485 return 'disabled'
486
487
488 class ReportableChanges(Changes):
489 @property
490 def bind_password(self):
491 return None
492
493 @property
494 def validate_certs(self):
495 return flatten_boolean(self._values['validate_certs'])
496
497 @property
498 def referrals(self):
499 return flatten_boolean(self._values['referrals'])
500
501 @property
502 def check_member_attr(self):
503 return flatten_boolean(self._values['check_member_attr'])
504
505 @property
506 def ssl(self):
507 if self._values['ssl'] is None:
508 return None
509 elif self._values['ssl'] == 'start-tls':
510 return 'start-tls'
511 return flatten_boolean(self._values['ssl'])
512
513
514 class Difference(object):
515 def __init__(self, want, have=None):
516 self.want = want
517 self.have = have
518
519 def compare(self, param):
520 try:
521 result = getattr(self, param)
522 return result
523 except AttributeError:
524 return self.__default(param)
525
526 def __default(self, param):
527 attr1 = getattr(self.want, param)
528 try:
529 attr2 = getattr(self.have, param)
530 if attr1 != attr2:
531 return attr1
532 except AttributeError:
533 return attr1
534
535 @property
536 def login_ldap_attr(self):
537 return cmp_str_with_none(self.want.login_ldap_attr, self.have.login_ldap_attr)
538
539 @property
540 def user_template(self):
541 return cmp_str_with_none(self.want.user_template, self.have.user_template)
542
543 @property
544 def ca_cert(self):
545 return cmp_str_with_none(self.want.ca_cert, self.have.ca_cert)
546
547 @property
548 def client_key(self):
549 return cmp_str_with_none(self.want.client_key, self.have.client_key)
550
551 @property
552 def client_cert(self):
553 return cmp_str_with_none(self.want.client_cert, self.have.client_cert)
554
555 @property
556 def bind_password(self):
557 if self.want.bind_password != self.have.bind_password and self.want.update_password == 'always':
558 return self.want.bind_password
559
560
561 class ModuleManager(object):
562 def __init__(self, *args, **kwargs):
563 self.module = kwargs.get('module', None)
564 self.client = F5RestClient(**self.module.params)
565 self.want = ModuleParameters(params=self.module.params)
566 self.have = ApiParameters()
567 self.changes = UsableChanges()
568
569 def _set_changed_options(self):
570 changed = {}
571 for key in Parameters.returnables:
572 if getattr(self.want, key) is not None:
573 changed[key] = getattr(self.want, key)
574 if changed:
575 self.changes = UsableChanges(params=changed)
576
577 def _update_changed_options(self):
578 diff = Difference(self.want, self.have)
579 updatables = Parameters.updatables
580 changed = dict()
581 for k in updatables:
582 change = diff.compare(k)
583 if change is None:
584 continue
585 else:
586 if isinstance(change, dict):
587 changed.update(change)
588 else:
589 changed[k] = change
590 if changed:
591 self.changes = UsableChanges(params=changed)
592 return True
593 return False
594
595 def _announce_deprecations(self, result):
596 warnings = result.pop('__warnings', [])
597 for warning in warnings:
598 self.client.module.deprecate(
599 msg=warning['msg'],
600 version=warning['version']
601 )
602
603 def update_auth_source_on_device(self, source):
604 """Set the system auth source.
605
606 Configuring the authentication source is only one step in the process of setting
607 up an auth source. The other step is to inform the system of the auth source
608 you want to use.
609
610 This method is used for situations where
611
612 * The ``use_for_auth`` parameter is set to ``yes``
613 * The ``use_for_auth`` parameter is set to ``no``
614 * The ``state`` parameter is set to ``absent``
615
616 When ``state`` equal to ``absent``, before you can delete the LDAP configuration,
617 you must set the system auth to "something else". The system ships with a system
618 auth called "local", so this is the logical "something else" to use.
619
620 When ``use_for_auth`` is no, the same situation applies as when ``state`` equal
621 to ``absent`` is done above.
622
623 When ``use_for_auth`` is ``yes``, this method will set the current system auth
624 state to the value of source_type.
625
626 Arguments:
627 source (string): The source that you want to set on the device.
628 """
629 params = dict(
630 type=source
631 )
632 uri = 'https://{0}:{1}/mgmt/tm/auth/source/'.format(
633 self.client.provider['server'],
634 self.client.provider['server_port']
635 )
636
637 resp = self.client.api.patch(uri, json=params)
638 try:
639 response = resp.json()
640 except ValueError as ex:
641 raise F5ModuleError(str(ex))
642
643 if resp.status in [200, 201] or 'code' in response and response['code'] in [200, 201]:
644 return True
645 raise F5ModuleError(resp.content)
646
647 def update_fallback_on_device(self, fallback):
648 params = dict(
649 fallback=fallback
650 )
651 uri = 'https://{0}:{1}/mgmt/tm/auth/source/'.format(
652 self.client.provider['server'],
653 self.client.provider['server_port']
654 )
655
656 resp = self.client.api.patch(uri, json=params)
657 try:
658 response = resp.json()
659 except ValueError as ex:
660 raise F5ModuleError(str(ex))
661
662 if resp.status in [200, 201] or 'code' in response and response['code'] in [200, 201]:
663 return True
664 raise F5ModuleError(resp.content)
665
666 def exec_module(self):
667 start = datetime.now().isoformat()
668 version = tmos_version(self.client)
669 changed = False
670 result = dict()
671 state = self.want.state
672
673 if state == "present":
674 changed = self.present()
675 elif state == "absent":
676 changed = self.absent()
677
678 reportable = ReportableChanges(params=self.changes.to_return())
679 changes = reportable.to_return()
680 result.update(**changes)
681 result.update(dict(changed=changed))
682 self._announce_deprecations(result)
683 send_teem(start, self.client, self.module, version)
684 return result
685
686 def present(self):
687 if self.exists():
688 return self.update()
689 else:
690 return self.create()
691
692 def absent(self):
693 if self.exists():
694 return self.remove()
695 return False
696
697 def should_update(self):
698 result = self._update_changed_options()
699 if result:
700 return True
701 return False
702
703 def update(self):
704 self.have = self.read_current_from_device()
705 if not self.should_update():
706 return False
707 if self.module.check_mode:
708 return True
709 self.update_on_device()
710 if self.want.fallback_to_local == 'yes':
711 self.update_fallback_on_device('true')
712 elif self.want.fallback_to_local == 'no':
713 self.update_fallback_on_device('false')
714 if self.want.use_for_auth and self.changes.auth_source:
715 self.update_auth_source_on_device(self.changes.auth_source)
716 return True
717
718 def remove(self):
719 if self.module.check_mode:
720 return True
721 self.update_auth_source_on_device('local')
722 self.remove_from_device()
723 if self.exists():
724 raise F5ModuleError("Failed to delete the resource.")
725 return True
726
727 def create(self):
728 self._set_changed_options()
729 if self.module.check_mode:
730 return True
731 self.create_on_device()
732 if self.want.fallback_to_local == 'yes':
733 self.update_fallback_on_device('true')
734 elif self.want.fallback_to_local == 'no':
735 self.update_fallback_on_device('false')
736 if self.want.use_for_auth:
737 self.update_auth_source_on_device(self.want.auth_source)
738 return True
739
740 def exists(self):
741 errors = [401, 403, 409, 500, 501, 502, 503, 504]
742 uri = "https://{0}:{1}/mgmt/tm/auth/ldap/{2}".format(
743 self.client.provider['server'],
744 self.client.provider['server_port'],
745 transform_name('Common', 'system-auth')
746 )
747 resp = self.client.api.get(uri)
748 try:
749 response = resp.json()
750 except ValueError as ex:
751 raise F5ModuleError(str(ex))
752
753 if resp.status == 404 or 'code' in response and response['code'] == 404:
754 return False
755 if resp.status in [200, 201] or 'code' in response and response['code'] in [200, 201]:
756 return True
757
758 if resp.status in errors or 'code' in response and response['code'] in errors:
759 if 'message' in response:
760 raise F5ModuleError(response['message'])
761 else:
762 raise F5ModuleError(resp.content)
763
764 def create_on_device(self):
765 params = self.changes.api_params()
766 params['name'] = 'system-auth'
767 params['partition'] = 'Common'
768 uri = "https://{0}:{1}/mgmt/tm/auth/ldap/".format(
769 self.client.provider['server'],
770 self.client.provider['server_port'],
771 )
772 resp = self.client.api.post(uri, json=params)
773 try:
774 response = resp.json()
775 except ValueError as ex:
776 raise F5ModuleError(str(ex))
777
778 if resp.status in [200, 201] or 'code' in response and response['code'] in [200, 201]:
779 return True
780 raise F5ModuleError(resp.content)
781
782 def update_on_device(self):
783 params = self.changes.api_params()
784 if not params:
785 return
786 uri = "https://{0}:{1}/mgmt/tm/auth/ldap/{2}".format(
787 self.client.provider['server'],
788 self.client.provider['server_port'],
789 transform_name('Common', 'system-auth')
790 )
791 resp = self.client.api.patch(uri, json=params)
792 try:
793 response = resp.json()
794 except ValueError as ex:
795 raise F5ModuleError(str(ex))
796
797 if resp.status in [200, 201] or 'code' in response and response['code'] in [200, 201]:
798 return True
799 raise F5ModuleError(resp.content)
800
801 def remove_from_device(self):
802 uri = "https://{0}:{1}/mgmt/tm/auth/ldap/{2}".format(
803 self.client.provider['server'],
804 self.client.provider['server_port'],
805 transform_name('Common', 'system-auth')
806 )
807 response = self.client.api.delete(uri)
808
809 if response.status in [200, 201]:
810 return True
811 raise F5ModuleError(response.content)
812
813 def read_current_from_device(self):
814 uri = "https://{0}:{1}/mgmt/tm/auth/ldap/{2}".format(
815 self.client.provider['server'],
816 self.client.provider['server_port'],
817 transform_name('Common', 'system-auth')
818 )
819 resp = self.client.api.get(uri)
820 try:
821 response = resp.json()
822 except ValueError as ex:
823 raise F5ModuleError(str(ex))
824
825 if resp.status in [200, 201] or 'code' in response and response['code'] in [200, 201]:
826 response.update(self.read_current_auth_source_from_device())
827 return ApiParameters(params=response)
828 raise F5ModuleError(resp.content)
829
830 def read_current_auth_source_from_device(self):
831 uri = "https://{0}:{1}/mgmt/tm/auth/source".format(
832 self.client.provider['server'],
833 self.client.provider['server_port'],
834 )
835 resp = self.client.api.get(uri)
836 try:
837 response = resp.json()
838 except ValueError as ex:
839 raise F5ModuleError(str(ex))
840 result = {}
841 if resp.status in [200, 201] or 'code' in response and response['code'] in [200, 201]:
842 if 'fallback' in response:
843 result['fallback'] = response['fallback']
844 if 'type' in response:
845 result['auth_source'] = response['type']
846 return result
847 raise F5ModuleError(resp.content)
848
849
850 class ArgumentSpec(object):
851 def __init__(self):
852 self.supports_check_mode = True
853 argument_spec = dict(
854 servers=dict(
855 type='list',
856 elements='str',
857 ),
858 port=dict(type='int'),
859 remote_directory_tree=dict(),
860 scope=dict(
861 choices=['sub', 'one', 'base']
862 ),
863 bind_dn=dict(),
864 source_type=dict(
865 default='ldap',
866 choices=['ldap', 'active-directory']
867 ),
868 bind_password=dict(no_log=True),
869 user_template=dict(),
870 check_member_attr=dict(type='bool'),
871 ssl=dict(
872 choices=['yes', 'no', 'start-tls']
873 ),
874 ca_cert=dict(aliases=['ssl_ca_cert']),
875 client_key=dict(aliases=['ssl_client_key'], no_log=True),
876 client_cert=dict(aliases=['ssl_client_cert']),
877 validate_certs=dict(type='bool', aliases=['ssl_check_peer']),
878 login_ldap_attr=dict(),
879 fallback_to_local=dict(type='bool'),
880 referrals=dict(type='bool'),
881 use_for_auth=dict(type='bool'),
882 update_password=dict(
883 default='always',
884 choices=['always', 'on_create'],
885 no_log=False
886 ),
887 state=dict(default='present', choices=['absent', 'present']),
888 )
889 self.argument_spec = {}
890 self.argument_spec.update(f5_argument_spec)
891 self.argument_spec.update(argument_spec)
892
893
894 def main():
895 spec = ArgumentSpec()
896
897 module = AnsibleModule(
898 argument_spec=spec.argument_spec,
899 supports_check_mode=spec.supports_check_mode,
900 )
901
902 try:
903 mm = ModuleManager(module=module)
904 results = mm.exec_module()
905 module.exit_json(**results)
906 except F5ModuleError as ex:
907 module.fail_json(msg=str(ex))
908
909
910 if __name__ == '__main__':
911 main()