mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-25 11:51:26 -07:00
Fix undefined variables, basestring usage, and some associated python3 issues
This commit is contained in:
parent
9f7b0dfc30
commit
225fa5d092
84 changed files with 652 additions and 963 deletions
|
@ -156,8 +156,7 @@ RETURN = """
|
|||
# Default return values
|
||||
"""
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.pycompat24 import get_exception
|
||||
import traceback
|
||||
|
||||
try:
|
||||
import ldap
|
||||
|
@ -168,6 +167,10 @@ try:
|
|||
except ImportError:
|
||||
HAS_LDAP = False
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.six import string_types
|
||||
from ansible.module_utils._text import to_native
|
||||
|
||||
|
||||
class LdapEntry(object):
|
||||
def __init__(self, module):
|
||||
|
@ -251,19 +254,19 @@ class LdapEntry(object):
|
|||
if self.start_tls:
|
||||
try:
|
||||
connection.start_tls_s()
|
||||
except ldap.LDAPError:
|
||||
e = get_exception()
|
||||
self.module.fail_json(msg="Cannot start TLS.", details=str(e))
|
||||
except ldap.LDAPError as e:
|
||||
self.module.fail_json(msg="Cannot start TLS.", details=to_native(e),
|
||||
exception=traceback.format_exc())
|
||||
|
||||
try:
|
||||
if self.bind_dn is not None:
|
||||
connection.simple_bind_s(self.bind_dn, self.bind_pw)
|
||||
else:
|
||||
connection.sasl_interactive_bind_s('', ldap.sasl.external())
|
||||
except ldap.LDAPError:
|
||||
e = get_exception()
|
||||
except ldap.LDAPError as e:
|
||||
self.module.fail_json(
|
||||
msg="Cannot bind to the server.", details=str(e))
|
||||
msg="Cannot bind to the server.", details=to_native(e),
|
||||
exception=traceback.format_exc())
|
||||
|
||||
return connection
|
||||
|
||||
|
@ -298,7 +301,7 @@ def main():
|
|||
# Check if objectClass is of the correct type
|
||||
if (
|
||||
module.params['objectClass'] is not None and not (
|
||||
isinstance(module.params['objectClass'], basestring) or
|
||||
isinstance(module.params['objectClass'], string_types) or
|
||||
isinstance(module.params['objectClass'], list))):
|
||||
module.fail_json(msg="objectClass must be either a string or a list.")
|
||||
|
||||
|
@ -326,9 +329,8 @@ def main():
|
|||
if action is not None and not module.check_mode:
|
||||
try:
|
||||
action()
|
||||
except Exception:
|
||||
e = get_exception()
|
||||
module.fail_json(msg="Entry action failed.", details=str(e))
|
||||
except Exception as e:
|
||||
module.fail_json(msg="Entry action failed.", details=to_native(e), exception=traceback.format_exc())
|
||||
|
||||
module.exit_json(changed=(action is not None))
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue