Fix undefined variables, basestring usage, and some associated python3 issues

This commit is contained in:
Toshio Kuratomi 2017-07-22 18:15:46 -07:00
commit 225fa5d092
84 changed files with 652 additions and 963 deletions

View file

@ -81,8 +81,9 @@ EXAMPLES = '''
'''
import re
from ansible.module_utils.basic import *
from ansible.module_utils.pycompat24 import get_exception
import subprocess
from ansible.module_utils.basic import AnsibleModule
def main():
@ -161,8 +162,7 @@ def main():
)
module.exit_json(changed=True)
except subprocess.CalledProcessError:
e = get_exception()
except subprocess.CalledProcessError as cpe:
module.fail_json(msg=str(dir(cpe)))
else:
module.exit_json(changed=False)

View file

@ -120,7 +120,8 @@ import datetime
import re
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.pycompat24 import get_exception
from ansible.module_utils.six import binary_type, text_type
# exceptions --------------------------------------------------------------- {{{
class OSXDefaultsException(Exception):
@ -169,7 +170,7 @@ class OSXDefaults(object):
if type == "string":
return str(value)
elif type in ["bool", "boolean"]:
if isinstance(value, basestring):
if isinstance(value, (binary_type, text_type)):
value = value.lower()
if value in [True, 1, "true", "1", "yes"]:
return True
@ -414,8 +415,7 @@ def main():
array_add=array_add, value=value, state=state, path=path)
changed = defaults.run()
module.exit_json(changed=changed)
except OSXDefaultsException:
e = get_exception()
except OSXDefaultsException as e:
module.fail_json(msg=e.message)
# /main ------------------------------------------------------------------- }}}

View file

@ -61,6 +61,8 @@ EXAMPLES = '''
persistent: yes
'''
import os
try:
import selinux
HAVE_SELINUX=True
@ -73,6 +75,11 @@ try:
except ImportError:
HAVE_SEMANAGE=False
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.six import binary_type
from ansible.module_utils._text import to_bytes
def has_boolean_value(module, name):
bools = []
try:
@ -151,8 +158,7 @@ def semanage_boolean_value(module, name, state):
semanage.semanage_disconnect(handle)
semanage.semanage_handle_destroy(handle)
except Exception:
e = get_exception()
except Exception as e:
module.fail_json(msg="Failed to manage policy for boolean %s: %s" % (name, str(e)))
return True
@ -219,17 +225,13 @@ def main():
result['changed'] = r
if not r:
module.fail_json(msg="Failed to set boolean %s to %s" % (name, value))
module.fail_json(msg="Failed to set boolean %s to %s" % (name, state))
try:
selinux.security_commit_booleans()
except:
module.fail_json(msg="Failed to commit pending boolean %s value" % name)
module.exit_json(**result)
# import module snippets
from ansible.module_utils.basic import *
from ansible.module_utils._text import to_bytes
from ansible.module_utils.six import binary_type
if __name__ == '__main__':
main()