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
pull/21336/merge
Toshio Kuratomi 7 years ago
parent ff22528b07
commit d64e291274

@ -140,20 +140,24 @@ import json
import traceback
try:
import boto3
import botocore
HAS_BOTO3 = True
except ImportError:
HAS_BOTO3 = False
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.ec2 import boto3_conn, ec2_argument_spec, get_aws_connection_info
from ansible.module_utils._text import to_native
def main():
argument_spec = ec2_argument_spec()
argument_spec.update(dict(
name = dict(),
function_arn = dict(),
wait = dict(choices=BOOLEANS, default=True, type='bool'),
tail_log = dict(choices=BOOLEANS, default=False, type='bool'),
dry_run = dict(choices=BOOLEANS, default=False, type='bool'),
wait = dict(default=True, type='bool'),
tail_log = dict(default=False, type='bool'),
dry_run = dict(default=False, type='bool'),
version_qualifier = dict(),
payload = dict(default={}, type='dict'),
))
@ -192,7 +196,7 @@ def main():
client = boto3_conn(module, conn_type='client', resource='lambda',
region=region, endpoint=ec2_url, **aws_connect_kwargs)
except (botocore.exceptions.ClientError, botocore.exceptions.ValidationError) as e:
module.fail_json(msg="Failure connecting boto3 to AWS", exception=traceback.format_exc())
module.fail_json(msg="Failure connecting boto3 to AWS: %s" % to_native(e), exception=traceback.format_exc())
invoke_params = {}
@ -282,9 +286,6 @@ def main():
module.exit_json(changed=True, result=results)
# import module snippets
from ansible.module_utils.basic import *
from ansible.module_utils.ec2 import *
if __name__ == '__main__':
main()

@ -352,7 +352,7 @@ def main():
healthchecks=dict(type='list', required=True),
service_account_email=dict(),
service_account_permissions=dict(type='list'),
enable_cdn=dict(type='bool', choices=[True, False]),
enable_cdn=dict(type='bool'),
port_name=dict(type='str'),
protocol=dict(type='str', default='TCP',
choices=['HTTP', 'HTTPS', 'SSL', 'TCP']),

@ -431,7 +431,13 @@ lxc_container:
sample: True
"""
import os
import os.path
import re
import shutil
import subprocess
import tempfile
import time
try:
import lxc
@ -440,6 +446,10 @@ except ImportError:
else:
HAS_LXC = True
# import module bits
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.parsing.convert_bool import BOOLEANS_FALSE, BOOLEANS_TRUE
# LXC_COMPRESSION_MAP is a map of available compression types when creating
# an archive of a container.
@ -562,11 +572,6 @@ def create_script(command):
:type command: ``str``
"""
import os
import os.path as path
import subprocess
import tempfile
(fd, script_file) = tempfile.mkstemp(prefix='lxc-attach-script')
f = os.fdopen(fd, 'wb')
try:
@ -682,7 +687,7 @@ class LxcContainerManagement(object):
variables.pop(v, None)
return_dict = dict()
false_values = [None, ''] + BOOLEANS_FALSE
false_values = BOOLEANS_FALSE.union([None, ''])
for k, v in variables.items():
_var = self.module.params.get(k)
if _var not in false_values:
@ -1761,7 +1766,5 @@ def main():
lxc_manage.run()
# import module bits
from ansible.module_utils.basic import *
if __name__ == '__main__':
main()

@ -531,7 +531,10 @@ import socket
import sys
import types
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.six.moves.urllib.parse import urlencode
from ansible.module_utils.urls import open_url
HAS_LIB_JSON = True
try:
@ -604,8 +607,7 @@ class LogicMonitor(object):
self.fail(msg="Error: " + resp["errmsg"])
else:
return raw
except IOError:
ioe = get_exception()
except IOError as ioe:
self.fail(msg="Error: Exception making RPC call to " +
"https://" + self.company + "." + self.lm_url +
"/rpc/" + action + "\nException" + str(ioe))
@ -633,8 +635,7 @@ class LogicMonitor(object):
"https://" + self.company + "." + self.lm_url +
"/do/" + action + "?" + param_str)
return f.read()
except IOError:
ioe = get_exception()
except IOError as ioe:
self.fail(msg="Error: Exception making RPC call to " +
"https://" + self.company + "." + self.lm_url +
"/do/" + action + "\nException" + str(ioe))
@ -2171,7 +2172,7 @@ def main():
duration=dict(required=False, default=30),
properties=dict(required=False, default={}, type="dict"),
groups=dict(required=False, default=[], type="list"),
alertenable=dict(required=False, default="true", choices=BOOLEANS)
alertenable=dict(required=False, default="true", type="bool")
),
supports_check_mode=True
)
@ -2182,10 +2183,5 @@ def main():
selector(module)
from ansible.module_utils.basic import *
from ansible.module_utils.urls import *
from ansible.module_utils.urls import open_url
if __name__ == "__main__":
main()

@ -216,6 +216,12 @@ msg:
sample: "interface bond0 config updated"
'''
import os
import re
import tempfile
from ansible.module_utils.basic import AnsibleModule
# handy helper for calling system calls.
# calls AnsibleModule.run_command and prints a more appropriate message
@ -437,9 +443,9 @@ def main():
virtual_mac=dict(type='str'),
vids=dict(type='list'),
pvid=dict(type='str'),
mstpctl_portnetwork=dict(type='bool', choices=BOOLEANS),
mstpctl_portadminedge=dict(type='bool', choices=BOOLEANS),
mstpctl_bpduguard=dict(type='bool', choices=BOOLEANS),
mstpctl_portnetwork=dict(type='bool'),
mstpctl_portadminedge=dict(type='bool'),
mstpctl_bpduguard=dict(type='bool'),
clag_id=dict(type='str'),
min_links=dict(type='int', default=1),
mode=dict(type='str', default='802.3ad'),
@ -484,11 +490,6 @@ def main():
module.exit_json(changed=_changed, msg=_msg)
# import module snippets
from ansible.module_utils.basic import *
import tempfile
import os
import re
if __name__ == '__main__':
main()

@ -164,6 +164,12 @@ msg:
sample: "interface bond0 config updated"
'''
import os
import re
import tempfile
from ansible.module_utils.basic import AnsibleModule
# handy helper for calling system calls.
# calls AnsibleModule.run_command and prints a more appropriate message
@ -373,8 +379,8 @@ def main():
vids=dict(type='list'),
pvid=dict(type='str'),
mstpctl_treeprio=dict(type='str'),
vlan_aware=dict(type='bool', choices=BOOLEANS),
stp=dict(type='bool', default='yes', choices=BOOLEANS),
vlan_aware=dict(type='bool'),
stp=dict(type='bool', default='yes'),
location=dict(type='str',
default='/etc/network/interfaces.d')
),
@ -410,11 +416,6 @@ def main():
module.exit_json(changed=_changed, msg=_msg)
# import module snippets
from ansible.module_utils.basic import *
import tempfile
import os
import re
if __name__ == '__main__':
main()

@ -110,6 +110,14 @@ msg:
sample: "interface bond0 config updated"
'''
import re
from urlparse import urlparse
# import module snippets
from ansible.module_utils.basic import AnsibleModule, platform
# incompatible with ansible 1.4.4 - ubuntu 12.04 version
# from ansible.module_utils.urls import *
def check_url(module, url):
parsed_url = urlparse(url)
@ -124,8 +132,7 @@ def check_url(module, url):
def run_cl_cmd(module, cmd, check_rc=True):
try:
(rc, out, err) = module.run_command(cmd, check_rc=check_rc)
except Exception:
e = get_exception()
except Exception as e:
module.fail_json(msg=e.strerror)
# trim last line as it is always empty
ret = out.splitlines()
@ -301,7 +308,7 @@ def main():
argument_spec=dict(
src=dict(required=True, type='str'),
version=dict(type='str'),
switch_slot=dict(type='bool', choices=BOOLEANS, default=False),
switch_slot=dict(type='bool', default=False),
),
)
@ -315,12 +322,5 @@ def main():
install_img(module)
# import module snippets
from ansible.module_utils.basic import *
# incompatible with ansible 1.4.4 - ubuntu 12.04 version
# from ansible.module_utils.urls import *
from urlparse import urlparse
import re
if __name__ == '__main__':
main()

@ -209,6 +209,13 @@ msg:
sample: "interface bond0 config updated"
'''
import os
import platform
import re
import tempfile
from ansible.module_utils.basic import AnsibleModule
# handy helper for calling system calls.
# calls AnsibleModule.run_command and prints a more appropriate message
@ -401,10 +408,10 @@ def main():
virtual_mac=dict(type='str'),
vids=dict(type='list'),
pvid=dict(type='str'),
mstpctl_portnetwork=dict(type='bool', choices=BOOLEANS),
mstpctl_portadminedge=dict(type='bool', choices=BOOLEANS),
mstpctl_bpduguard=dict(type='bool', choices=BOOLEANS),
clagd_enable=dict(type='bool', choices=BOOLEANS),
mstpctl_portnetwork=dict(type='bool'),
mstpctl_portadminedge=dict(type='bool'),
mstpctl_bpduguard=dict(type='bool'),
clagd_enable=dict(type='bool'),
clagd_priority=dict(type='str'),
clagd_peer_ip=dict(type='str'),
clagd_sys_mac=dict(type='str'),
@ -446,10 +453,6 @@ def main():
module.exit_json(changed=_changed, msg=_msg)
# import module snippets
from ansible.module_utils.basic import *
import tempfile
import os
if __name__ == '__main__':
main()

@ -107,6 +107,9 @@ msg:
sample: "interface bond0 config updated"
'''
# import module snippets
from ansible.module_utils.basic import AnsibleModule
CL_LICENSE_PATH='/usr/cumulus/bin/cl-license'
def install_license(module):
@ -121,8 +124,7 @@ def main():
module = AnsibleModule(
argument_spec=dict(
src=dict(required=True, type='str'),
force=dict(type='bool', choices=BOOLEANS,
default=False)
force=dict(type='bool', default=False)
),
)
@ -142,9 +144,5 @@ def main():
module.exit_json(changed=module.changed, msg=module.msg)
# import module snippets
from ansible.module_utils.basic import *
# from ansible.module_utils.urls import *
if __name__ == '__main__':
main()

@ -146,7 +146,6 @@ from ansible.module_utils.f5_utils import (
iteritems,
defaultdict
)
from ansible.module_utils.basic import BOOLEANS
class Parameters(AnsibleF5Parameters):

@ -118,6 +118,10 @@ try:
except ImportError:
HAS_F5SDK = False
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.ec2 import camel_dict_to_snake_dict
from ansible.module_utils.f5_utils import F5ModuleError, f5_argument_spec
class BigIpGtmDatacenter(object):
def __init__(self, *args, **kwargs):
@ -346,7 +350,7 @@ def main():
meta_args = dict(
contact=dict(required=False, default=None),
description=dict(required=False, default=None),
enabled=dict(required=False, type='bool', default=None, choices=BOOLEANS),
enabled=dict(required=False, type='bool', default=None),
location=dict(required=False, default=None),
name=dict(required=True)
)
@ -365,9 +369,6 @@ def main():
except F5ModuleError as e:
module.fail_json(msg=str(e))
from ansible.module_utils.basic import *
from ansible.module_utils.ec2 import camel_dict_to_snake_dict
from ansible.module_utils.f5_utils import *
if __name__ == '__main__':
main()

@ -118,7 +118,15 @@ RETURN = '''
import re
import uuid
from ansible.module_utils.basic import BOOLEANS
try:
from StringIO import StringIO
except ImportError:
from io import StringIO
from f5.utils.iapp_parser import (
NonextantTemplateNameException
)
from ansible.module_utils.f5_utils import (
AnsibleF5Client,
AnsibleF5Parameters,
@ -128,14 +136,6 @@ from ansible.module_utils.f5_utils import (
defaultdict,
iControlUnexpectedHTTPError
)
from f5.utils.iapp_parser import (
NonextantTemplateNameException
)
try:
from StringIO import StringIO
except ImportError:
from io import StringIO
class Parameters(AnsibleF5Parameters):
@ -453,7 +453,6 @@ class ArgumentSpec(object):
choices=['present', 'absent']
),
force=dict(
choices=BOOLEANS,
type='bool'
),
content=dict()

@ -138,6 +138,10 @@ try:
except ImportError:
HAS_NETADDR = False
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.ec2 import camel_dict_to_snake_dict
from ansible.module_utils.f5_utils import F5ModuleError, f5_argument_spec
class BigIpSnatPoolManager(object):
def __init__(self, *args, **kwargs):
@ -363,7 +367,6 @@ class BigIpSnatPoolModuleConfig(object):
append=dict(
default=False,
type='bool',
choices=BOOLEANS
),
name=dict(required=True),
members=dict(
@ -410,9 +413,6 @@ def main():
except F5ModuleError as e:
module.fail_json(msg=str(e))
from ansible.module_utils.basic import *
from ansible.module_utils.ec2 import camel_dict_to_snake_dict
from ansible.module_utils.f5_utils import *
if __name__ == '__main__':
main()

@ -196,8 +196,6 @@ try:
except ImportError:
HAS_NETADDR = False
from ansible.module_utils.basic import BOOLEANS_TRUE
from ansible.module_utils.basic import BOOLEANS_FALSE
from ansible.module_utils.f5_utils import (
AnsibleF5Client,
AnsibleF5Parameters,
@ -205,6 +203,7 @@ from ansible.module_utils.f5_utils import (
F5ModuleError,
iControlUnexpectedHTTPError
)
from ansible.module_utils.parsing.convert_bool import BOOLEANS_FALSE, BOOLEANS_TRUE
class Parameters(AnsibleF5Parameters):

@ -231,7 +231,7 @@ def main():
link=dict(required=True, default=None, type='str', aliases=['nic', 'interface']),
property=dict(required=True, type='str', aliases=['name']),
value=dict(required=False, type='str'),
temporary=dict(default=False, type='bool', choices=BOOLEANS),
temporary=dict(default=False, type='bool'),
state=dict(
default='present', choices=['absent', 'present', 'reset']),
),
@ -298,6 +298,5 @@ def main():
module.exit_json(**result)
if __name__ == '__main__':
main()

@ -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

@ -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()

Loading…
Cancel
Save