Fix modules' use of BOOLEANS*

* The canonical location of BOOLEANS has moved.  Switch imports to use that.
* clean up argument_spec use of booleans.
* Clean up imports to not use wildcards
* Remove usage of get_exception
This commit is contained in:
Toshio Kuratomi 2017-07-14 16:42:00 -07:00
parent ff22528b07
commit d64e291274
17 changed files with 98 additions and 102 deletions

View file

@ -104,8 +104,7 @@ RETURN = '''
...
'''
from ansible.module_utils.basic import AnsibleModule, BOOLEANS_TRUE
from ansible.module_utils.pycompat24 import get_exception
from ansible.module_utils.basic import AnsibleModule
class GConf2Preference(object):
@ -165,8 +164,7 @@ class GConf2Preference(object):
else:
changed = True
except OSError:
exception = get_exception()
except OSError as exception:
self.ansible.fail_json(msg='gconftool-2 failed with exception: '
'%s' % exception)
return changed, out.rstrip()
@ -193,7 +191,6 @@ def main():
state_values = {"present": "set", "absent": "unset", "get": "get"}
direct = False
# Assign module values to dictionary values
key = module.params['key']
value_type = module.params['value_type']
@ -205,8 +202,7 @@ def main():
value = module.params['value']
state = state_values[module.params['state']]
if module.params['direct'] in BOOLEANS_TRUE:
direct = True
direct = module.params['direct']
config_source = module.params['config_source']
# Initialize some variables for later

View file

@ -118,8 +118,10 @@ EXAMPLES = '''
import os
import tempfile
from ansible.module_utils.basic import get_platform, get_exception, AnsibleModule, BOOLEANS_TRUE, BOOLEANS_FALSE
from ansible.module_utils.basic import get_platform, AnsibleModule
from ansible.module_utils.six import string_types
from ansible.module_utils.parsing.convert_bool import BOOLEANS_FALSE, BOOLEANS_TRUE
class SysctlModule(object):
@ -309,8 +311,7 @@ class SysctlModule(object):
f = open(self.sysctl_file, "r")
lines = f.readlines()
f.close()
except IOError:
e = get_exception()
except IOError as e:
self.module.fail_json(msg="Failed to open %s: %s" % (self.sysctl_file, str(e)))
for line in lines:
@ -335,7 +336,7 @@ class SysctlModule(object):
self.fixed_lines.append(line)
continue
tmpline = line.strip()
k, v = line.split('=',1)
k, v = tmpline.split('=',1)
k = k.strip()
v = v.strip()
if k not in checked:
@ -360,8 +361,7 @@ class SysctlModule(object):
try:
for l in self.fixed_lines:
f.write(l.strip() + "\n")
except IOError:
e = get_exception()
except IOError as e:
self.module.fail_json(msg="Failed to write to file %s: %s" % (tmp_path, str(e)))
f.flush()
f.close()