mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-25 14:20:22 -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
|
@ -184,6 +184,7 @@ import traceback
|
|||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.ec2 import get_aws_connection_info, boto3_conn, ec2_argument_spec, HAS_BOTO3
|
||||
from ansible.module_utils.ec2 import camel_dict_to_snake_dict
|
||||
from ansible.module_utils.six import string_types
|
||||
|
||||
try:
|
||||
import botocore
|
||||
|
@ -309,7 +310,7 @@ def setup_removal(client, module):
|
|||
params = dict()
|
||||
changed = False
|
||||
params['DryRun'] = module.check_mode
|
||||
if isinstance(module.params.get('vpc_endpoint_id'), basestring):
|
||||
if isinstance(module.params.get('vpc_endpoint_id'), string_types):
|
||||
params['VpcEndpointIds'] = [module.params.get('vpc_endpoint_id')]
|
||||
else:
|
||||
params['VpcEndpointIds'] = module.params.get('vpc_endpoint_id')
|
||||
|
|
|
@ -138,7 +138,7 @@ def ensure_tags(vpc_conn, resource_id, tags, add_only, check_mode):
|
|||
latest_tags = get_resource_tags(vpc_conn, resource_id)
|
||||
return {'changed': True, 'tags': latest_tags}
|
||||
except EC2ResponseError as e:
|
||||
raise AnsibleTagCreationException(
|
||||
raise AnsibleIGWException(
|
||||
'Unable to update tags for {0}, error: {1}'.format(resource_id, e))
|
||||
|
||||
|
||||
|
|
|
@ -56,6 +56,7 @@ EXAMPLES = '''
|
|||
"tag:Name": Example
|
||||
|
||||
'''
|
||||
import traceback
|
||||
|
||||
try:
|
||||
import boto.vpc
|
||||
|
@ -66,6 +67,7 @@ except ImportError:
|
|||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.ec2 import connect_to_aws, ec2_argument_spec, get_aws_connection_info
|
||||
from ansible.module_utils._text import to_native
|
||||
|
||||
|
||||
def get_vpc_info(vpc):
|
||||
|
@ -121,8 +123,8 @@ def main():
|
|||
if region:
|
||||
try:
|
||||
connection = connect_to_aws(boto.vpc, region, **aws_connect_params)
|
||||
except (boto.exception.NoAuthHandlerFound, StandardError) as e:
|
||||
module.fail_json(msg=str(e))
|
||||
except (boto.exception.NoAuthHandlerFound, Exception) as e:
|
||||
module.fail_json(msg=to_native(e), exception=traceback.format_exc())
|
||||
else:
|
||||
module.fail_json(msg="region must be specified")
|
||||
|
||||
|
|
|
@ -119,6 +119,7 @@ tasks:
|
|||
'''
|
||||
import json
|
||||
import urllib
|
||||
|
||||
try:
|
||||
import boto
|
||||
import boto.iam
|
||||
|
@ -127,6 +128,11 @@ try:
|
|||
except ImportError:
|
||||
HAS_BOTO = False
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.ec2 import connect_to_aws, ec2_argument_spec, get_aws_connection_info
|
||||
from ansible.module_utils.six import string_types
|
||||
|
||||
|
||||
def boto_exception(err):
|
||||
'''generic error message handler'''
|
||||
if hasattr(err, 'error_message'):
|
||||
|
@ -317,7 +323,7 @@ def main():
|
|||
elif module.params.get('policy_json') is not None:
|
||||
pdoc = module.params.get('policy_json')
|
||||
# if its a string, assume it is already JSON
|
||||
if not isinstance(pdoc, basestring):
|
||||
if not isinstance(pdoc, string_types):
|
||||
try:
|
||||
pdoc = json.dumps(pdoc)
|
||||
except Exception as e:
|
||||
|
@ -353,8 +359,6 @@ def main():
|
|||
state)
|
||||
module.exit_json(changed=changed, group_name=name, policies=current_policies, msg=msg)
|
||||
|
||||
from ansible.module_utils.basic import *
|
||||
from ansible.module_utils.ec2 import *
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
@ -116,6 +116,20 @@ EXAMPLES = '''
|
|||
name: norwegian_blue
|
||||
'''
|
||||
|
||||
try:
|
||||
import boto.rds
|
||||
from boto.exception import BotoServerError
|
||||
HAS_BOTO = True
|
||||
except ImportError:
|
||||
HAS_BOTO = False
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.ec2 import connect_to_aws, ec2_argument_spec, get_aws_connection_info
|
||||
from ansible.module_utils.parsing.convert_bool import BOOLEANS_TRUE
|
||||
from ansible.module_utils.six import string_types
|
||||
from ansible.module_utils._text import to_native
|
||||
|
||||
|
||||
VALID_ENGINES = [
|
||||
'aurora5.6',
|
||||
'mariadb10.0',
|
||||
|
@ -147,12 +161,12 @@ VALID_ENGINES = [
|
|||
'sqlserver-web-12.0',
|
||||
]
|
||||
|
||||
try:
|
||||
import boto.rds
|
||||
from boto.exception import BotoServerError
|
||||
HAS_BOTO = True
|
||||
except ImportError:
|
||||
HAS_BOTO = False
|
||||
INT_MODIFIERS = {
|
||||
'K': 1024,
|
||||
'M': pow(1024, 2),
|
||||
'G': pow(1024, 3),
|
||||
'T': pow(1024, 4),
|
||||
}
|
||||
|
||||
|
||||
# returns a tuple: (whether or not a parameter was changed, the remaining parameters that weren't found in this parameter group)
|
||||
|
@ -168,14 +182,6 @@ class NotModifiableError(Exception):
|
|||
def __str__(self):
|
||||
return 'NotModifiableError: %s' % self.error_message
|
||||
|
||||
INT_MODIFIERS = {
|
||||
'K': 1024,
|
||||
'M': pow(1024, 2),
|
||||
'G': pow(1024, 3),
|
||||
'T': pow(1024, 4),
|
||||
}
|
||||
|
||||
TRUE_VALUES = ('on', 'true', 'yes', '1',)
|
||||
|
||||
def set_parameter(param, value, immediate):
|
||||
"""
|
||||
|
@ -187,7 +193,7 @@ def set_parameter(param, value, immediate):
|
|||
converted_value = str(value)
|
||||
|
||||
elif param.type == 'integer':
|
||||
if isinstance(value, basestring):
|
||||
if isinstance(value, string_types):
|
||||
try:
|
||||
for modifier in INT_MODIFIERS.keys():
|
||||
if value.endswith(modifier):
|
||||
|
@ -203,8 +209,8 @@ def set_parameter(param, value, immediate):
|
|||
converted_value = int(value)
|
||||
|
||||
elif param.type == 'boolean':
|
||||
if isinstance(value, basestring):
|
||||
converted_value = value in TRUE_VALUES
|
||||
if isinstance(value, string_types):
|
||||
converted_value = to_native(value) in BOOLEANS_TRUE
|
||||
else:
|
||||
converted_value = bool(value)
|
||||
|
||||
|
@ -337,9 +343,6 @@ def main():
|
|||
|
||||
module.exit_json(changed=changed)
|
||||
|
||||
# import module snippets
|
||||
from ansible.module_utils.basic import *
|
||||
from ansible.module_utils.ec2 import *
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
@ -184,22 +184,19 @@ uploaded:
|
|||
|
||||
'''
|
||||
|
||||
import datetime
|
||||
import fnmatch
|
||||
import hashlib
|
||||
import mimetypes
|
||||
import os
|
||||
import stat as osstat # os.stat constants
|
||||
import mimetypes
|
||||
import datetime
|
||||
from dateutil import tz
|
||||
import hashlib
|
||||
import fnmatch
|
||||
import traceback
|
||||
from dateutil import tz
|
||||
|
||||
# import module snippets
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.ec2 import ec2_argument_spec
|
||||
|
||||
# import a class, otherwise we'll use a fully qualified path
|
||||
# from ansible.module_utils.ec2 import AWSRetry
|
||||
import ansible.module_utils.ec2
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.ec2 import camel_dict_to_snake_dict, ec2_argument_spec
|
||||
|
||||
|
||||
try:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue