From 394e1e350c13395aa85539de6dcc9174900dbec2 Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Sat, 12 Aug 2017 09:27:11 -0700 Subject: [PATCH] Expand wildcard imports and add boilerplate More amazon modules with no open PRs. --- .../modules/cloud/amazon/ec2_vpc_vgw.py | 2 +- .../modules/cloud/amazon/ecs_attribute.py | 20 +++----- .../modules/cloud/amazon/ecs_cluster.py | 20 +++----- .../modules/cloud/amazon/ecs_service_facts.py | 19 ++------ lib/ansible/modules/cloud/amazon/ecs_task.py | 20 +++----- lib/ansible/modules/cloud/amazon/efs_facts.py | 32 +++++-------- .../cloud/amazon/elasticache_snapshot.py | 27 ++++------- .../cloud/amazon/elasticache_subnet_group.py | 27 ++++------- .../cloud/amazon/elb_application_lb.py | 2 +- .../cloud/amazon/elb_application_lb_facts.py | 27 ++++------- .../modules/cloud/amazon/elb_classic_lb.py | 35 +++++--------- .../modules/cloud/amazon/elb_instance.py | 27 ++++------- .../modules/cloud/amazon/elb_target_group.py | 30 +++++------- .../cloud/amazon/elb_target_group_facts.py | 27 ++++------- .../cloud/amazon/iam_managed_policy.py | 47 +++++++++---------- .../cloud/amazon/iam_mfa_device_facts.py | 28 ++++------- .../modules/cloud/amazon/lambda_alias.py | 34 ++++++-------- .../modules/cloud/amazon/lambda_event.py | 27 ++++------- lib/ansible/modules/cloud/amazon/lightsail.py | 26 ++++------ .../modules/cloud/amazon/rds_subnet_group.py | 28 ++++------- .../modules/cloud/amazon/redshift_facts.py | 29 ++++-------- .../cloud/amazon/redshift_subnet_group.py | 24 ++++------ lib/ansible/modules/cloud/amazon/route53.py | 36 ++++++-------- .../modules/cloud/amazon/route53_facts.py | 20 +++----- .../modules/cloud/amazon/s3_lifecycle.py | 22 ++++----- .../modules/cloud/amazon/s3_logging.py | 21 +++------ .../modules/cloud/amazon/s3_website.py | 29 +++++------- lib/ansible/modules/cloud/amazon/sns.py | 20 ++------ lib/ansible/modules/cloud/amazon/sns_topic.py | 20 +++----- lib/ansible/modules/cloud/amazon/sqs_queue.py | 20 +++----- .../modules/cloud/amazon/sts_assume_role.py | 20 +++----- .../modules/cloud/amazon/sts_session_token.py | 20 +++----- 32 files changed, 280 insertions(+), 506 deletions(-) diff --git a/lib/ansible/modules/cloud/amazon/ec2_vpc_vgw.py b/lib/ansible/modules/cloud/amazon/ec2_vpc_vgw.py index bf8ee76cdd..12d79fed3b 100644 --- a/lib/ansible/modules/cloud/amazon/ec2_vpc_vgw.py +++ b/lib/ansible/modules/cloud/amazon/ec2_vpc_vgw.py @@ -149,7 +149,7 @@ def get_vgw_info(vgws): def wait_for_status(client, module, vpn_gateway_id, status): polling_increment_secs = 15 - max_retries = (module.params.get('wait_timeout') / polling_increment_secs) + max_retries = (module.params.get('wait_timeout') // polling_increment_secs) status_achieved = False for x in range(0, max_retries): diff --git a/lib/ansible/modules/cloud/amazon/ecs_attribute.py b/lib/ansible/modules/cloud/amazon/ecs_attribute.py index a6210e2e60..b5ed3a8bb8 100644 --- a/lib/ansible/modules/cloud/amazon/ecs_attribute.py +++ b/lib/ansible/modules/cloud/amazon/ecs_attribute.py @@ -1,18 +1,10 @@ #!/usr/bin/python -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'status': ['preview'], 'supported_by': 'community', diff --git a/lib/ansible/modules/cloud/amazon/ecs_cluster.py b/lib/ansible/modules/cloud/amazon/ecs_cluster.py index d66413b925..a37a59a5ad 100644 --- a/lib/ansible/modules/cloud/amazon/ecs_cluster.py +++ b/lib/ansible/modules/cloud/amazon/ecs_cluster.py @@ -1,18 +1,10 @@ #!/usr/bin/python -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], diff --git a/lib/ansible/modules/cloud/amazon/ecs_service_facts.py b/lib/ansible/modules/cloud/amazon/ecs_service_facts.py index fa56b325ac..b4305f3c70 100644 --- a/lib/ansible/modules/cloud/amazon/ecs_service_facts.py +++ b/lib/ansible/modules/cloud/amazon/ecs_service_facts.py @@ -1,18 +1,9 @@ #!/usr/bin/python -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], diff --git a/lib/ansible/modules/cloud/amazon/ecs_task.py b/lib/ansible/modules/cloud/amazon/ecs_task.py index 4c3f805960..02e5519e32 100644 --- a/lib/ansible/modules/cloud/amazon/ecs_task.py +++ b/lib/ansible/modules/cloud/amazon/ecs_task.py @@ -1,18 +1,10 @@ #!/usr/bin/python -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], diff --git a/lib/ansible/modules/cloud/amazon/efs_facts.py b/lib/ansible/modules/cloud/amazon/efs_facts.py index 7e08ef7b5f..88bded433a 100644 --- a/lib/ansible/modules/cloud/amazon/efs_facts.py +++ b/lib/ansible/modules/cloud/amazon/efs_facts.py @@ -1,18 +1,10 @@ #!/usr/bin/python -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -165,18 +157,18 @@ tags: ''' -from time import sleep from collections import defaultdict - -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.ec2 import boto3_conn, get_aws_connection_info, ec2_argument_spec -from ansible.module_utils.ec2 import camel_dict_to_snake_dict, HAS_BOTO3 +from time import sleep try: from botocore.exceptions import ClientError -except ImportError as e: +except ImportError: pass # caught by imported HAS_BOTO3 +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.ec2 import (boto3_conn, get_aws_connection_info, ec2_argument_spec, + camel_dict_to_snake_dict, HAS_BOTO3) + class EFSConnection(object): STATE_CREATING = 'creating' diff --git a/lib/ansible/modules/cloud/amazon/elasticache_snapshot.py b/lib/ansible/modules/cloud/amazon/elasticache_snapshot.py index 3d64874c67..7f53660e5b 100644 --- a/lib/ansible/modules/cloud/amazon/elasticache_snapshot.py +++ b/lib/ansible/modules/cloud/amazon/elasticache_snapshot.py @@ -1,18 +1,10 @@ #!/usr/bin/python -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -124,9 +116,6 @@ changed: changed: true """ -# import module snippets -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.ec2 import boto3_conn, get_aws_connection_info, ec2_argument_spec, camel_dict_to_snake_dict import traceback try: @@ -136,6 +125,9 @@ try: except ImportError: HAS_BOTO3 = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.ec2 import boto3_conn, get_aws_connection_info, ec2_argument_spec, camel_dict_to_snake_dict + def create(module, connection, replication_id, cluster_id, name): """ Create an Elasticache backup. """ @@ -234,5 +226,6 @@ def main(): module.exit_json(**facts_result) + if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/amazon/elasticache_subnet_group.py b/lib/ansible/modules/cloud/amazon/elasticache_subnet_group.py index 18e89d9fa0..fb53d46374 100644 --- a/lib/ansible/modules/cloud/amazon/elasticache_subnet_group.py +++ b/lib/ansible/modules/cloud/amazon/elasticache_subnet_group.py @@ -1,18 +1,10 @@ #!/usr/bin/python -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -77,6 +69,10 @@ try: except ImportError: HAS_BOTO = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.ec2 import HAS_BOTO, ec2_argument_spec, get_aws_connection_info + + def main(): argument_spec = ec2_argument_spec() argument_spec.update(dict( @@ -149,9 +145,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() diff --git a/lib/ansible/modules/cloud/amazon/elb_application_lb.py b/lib/ansible/modules/cloud/amazon/elb_application_lb.py index 7c38b95e47..c78711c090 100755 --- a/lib/ansible/modules/cloud/amazon/elb_application_lb.py +++ b/lib/ansible/modules/cloud/amazon/elb_application_lb.py @@ -372,7 +372,7 @@ def convert_tg_name_to_arn(connection, module, tg_name): def wait_for_status(connection, module, elb_arn, status): polling_increment_secs = 15 - max_retries = module.params.get('wait_timeout') / polling_increment_secs + max_retries = module.params.get('wait_timeout') // polling_increment_secs status_achieved = False for x in range(0, max_retries): diff --git a/lib/ansible/modules/cloud/amazon/elb_application_lb_facts.py b/lib/ansible/modules/cloud/amazon/elb_application_lb_facts.py index a5f7e96429..be00f179a6 100644 --- a/lib/ansible/modules/cloud/amazon/elb_application_lb_facts.py +++ b/lib/ansible/modules/cloud/amazon/elb_application_lb_facts.py @@ -1,18 +1,10 @@ #!/usr/bin/python -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -160,9 +152,6 @@ load_balancers: ''' import traceback -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.ec2 import (boto3_conn, boto3_tag_list_to_ansible_dict, camel_dict_to_snake_dict, - ec2_argument_spec, get_aws_connection_info) try: import boto3 @@ -171,6 +160,10 @@ try: except ImportError: HAS_BOTO3 = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.ec2 import (boto3_conn, boto3_tag_list_to_ansible_dict, camel_dict_to_snake_dict, + ec2_argument_spec, get_aws_connection_info) + def get_elb_listeners(connection, module, elb_arn): diff --git a/lib/ansible/modules/cloud/amazon/elb_classic_lb.py b/lib/ansible/modules/cloud/amazon/elb_classic_lb.py index a524f8af01..f76858e6e4 100644 --- a/lib/ansible/modules/cloud/amazon/elb_classic_lb.py +++ b/lib/ansible/modules/cloud/amazon/elb_classic_lb.py @@ -1,18 +1,10 @@ #!/usr/bin/python -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['stableinterface'], @@ -394,6 +386,10 @@ EXAMPLES = """ tags: {} """ +import random +import time +import traceback + try: import boto import boto.ec2.elb @@ -405,13 +401,8 @@ try: except ImportError: HAS_BOTO = False -import time -import traceback -import random - from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.ec2 import ec2_argument_spec, connect_to_aws, AnsibleAWSError -from ansible.module_utils.ec2 import get_aws_connection_info +from ansible.module_utils.ec2 import ec2_argument_spec, connect_to_aws, AnsibleAWSError, get_aws_connection_info from ansible.module_utils.six import string_types from ansible.module_utils._text import to_native @@ -649,7 +640,7 @@ class ElbManager(object): @_throttleable_operation(_THROTTLING_RETRIES) def _wait_for_elb_removed(self): polling_increment_secs = 15 - max_retries = (self.wait_timeout / polling_increment_secs) + max_retries = (self.wait_timeout // polling_increment_secs) status_achieved = False for x in range(0, max_retries): @@ -667,7 +658,7 @@ class ElbManager(object): @_throttleable_operation(_THROTTLING_RETRIES) def _wait_for_elb_interface_removed(self): polling_increment_secs = 15 - max_retries = (self.wait_timeout / polling_increment_secs) + max_retries = (self.wait_timeout // polling_increment_secs) status_achieved = False elb_interfaces = self.ec2_conn.get_all_network_interfaces( diff --git a/lib/ansible/modules/cloud/amazon/elb_instance.py b/lib/ansible/modules/cloud/amazon/elb_instance.py index c1415adb68..d722aebcf6 100644 --- a/lib/ansible/modules/cloud/amazon/elb_instance.py +++ b/lib/ansible/modules/cloud/amazon/elb_instance.py @@ -1,18 +1,10 @@ #!/usr/bin/python -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['stableinterface'], @@ -113,6 +105,10 @@ try: except ImportError: HAS_BOTO = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.ec2 import (AnsibleAWSError, HAS_BOTO, connect_to_aws, ec2_argument_spec, + get_aws_connection_info) + class ElbManager: """Handles EC2 instance ELB registration and de-registration""" @@ -376,9 +372,6 @@ def main(): module.exit_json(**ec2_facts_result) -# import module snippets -from ansible.module_utils.basic import * -from ansible.module_utils.ec2 import * if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/amazon/elb_target_group.py b/lib/ansible/modules/cloud/amazon/elb_target_group.py index a8bc3b15ac..cdf719473d 100644 --- a/lib/ansible/modules/cloud/amazon/elb_target_group.py +++ b/lib/ansible/modules/cloud/amazon/elb_target_group.py @@ -1,18 +1,10 @@ #!/usr/bin/python -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'status': ['preview'], 'supported_by': 'community', @@ -277,9 +269,6 @@ vpc_id: sample: vpc-0123456 ''' -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.ec2 import boto3_conn, get_aws_connection_info, camel_dict_to_snake_dict, \ - ec2_argument_spec, boto3_tag_list_to_ansible_dict, compare_aws_tags, ansible_dict_to_boto3_tag_list import time import traceback @@ -290,6 +279,11 @@ try: except ImportError: HAS_BOTO3 = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.ec2 import (boto3_conn, get_aws_connection_info, camel_dict_to_snake_dict, + ec2_argument_spec, boto3_tag_list_to_ansible_dict, + compare_aws_tags, ansible_dict_to_boto3_tag_list) + def get_tg_attributes(connection, module, tg_arn): @@ -324,7 +318,7 @@ def get_target_group(connection, module): def wait_for_status(connection, module, target_group_arn, targets, status): polling_increment_secs = 5 - max_retries = (module.params.get('wait_timeout') / polling_increment_secs) + max_retries = (module.params.get('wait_timeout') // polling_increment_secs) status_achieved = False for x in range(0, max_retries): diff --git a/lib/ansible/modules/cloud/amazon/elb_target_group_facts.py b/lib/ansible/modules/cloud/amazon/elb_target_group_facts.py index e4f6e25bdf..dddc844a24 100644 --- a/lib/ansible/modules/cloud/amazon/elb_target_group_facts.py +++ b/lib/ansible/modules/cloud/amazon/elb_target_group_facts.py @@ -1,18 +1,10 @@ #!/usr/bin/python -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -171,9 +163,6 @@ target_groups: ''' import traceback -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.ec2 import (boto3_conn, boto3_tag_list_to_ansible_dict, camel_dict_to_snake_dict, - ec2_argument_spec, get_aws_connection_info) try: import boto3 @@ -182,6 +171,10 @@ try: except ImportError: HAS_BOTO3 = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.ec2 import (boto3_conn, boto3_tag_list_to_ansible_dict, camel_dict_to_snake_dict, + ec2_argument_spec, get_aws_connection_info) + def get_target_group_attributes(connection, module, target_group_arn): diff --git a/lib/ansible/modules/cloud/amazon/iam_managed_policy.py b/lib/ansible/modules/cloud/amazon/iam_managed_policy.py index c6e1d7c2f2..708cf40dea 100644 --- a/lib/ansible/modules/cloud/amazon/iam_managed_policy.py +++ b/lib/ansible/modules/cloud/amazon/iam_managed_policy.py @@ -1,18 +1,11 @@ #!/usr/bin/python -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + + ANSIBLE_METADATA = {'status': ['stableinterface'], 'supported_by': 'community', 'metadata_version': '1.0'} @@ -114,9 +107,6 @@ policy: }' ''' -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.ec2 import boto3_conn, get_aws_connection_info, ec2_argument_spec, AWSRetry -from ansible.module_utils.ec2 import sort_json_policy_dict, camel_dict_to_snake_dict, HAS_BOTO3 import json import traceback @@ -125,6 +115,11 @@ try: except ImportError: pass # caught by imported HAS_BOTO3 +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.ec2 import (boto3_conn, get_aws_connection_info, ec2_argument_spec, AWSRetry, + sort_json_policy_dict, camel_dict_to_snake_dict, HAS_BOTO3) +from ansible.module_utils._text import to_native + @AWSRetry.backoff(tries=5, delay=5, backoff=2.0) def list_policies_with_backoff(iam): @@ -318,8 +313,8 @@ def main(): try: rvalue = iam.create_policy(PolicyName=name, Path='/', PolicyDocument=policy, Description=description) - except: - module.fail_json(msg="Couldn't create policy %s: %s" % (name, str(e)), + except Exception as e: + module.fail_json(msg="Couldn't create policy %s: %s" % (name, to_native(e)), exception=traceback.format_exc(), **camel_dict_to_snake_dict(e.response)) @@ -332,8 +327,8 @@ def main(): if changed: try: p = iam.get_policy(PolicyArn=p['Arn'])['Policy'] - except: - module.fail_json(msg="Couldn't get policy: %s" % str(e), + except Exception as e: + module.fail_json(msg="Couldn't get policy: %s" % to_native(e), exception=traceback.format_exc(), **camel_dict_to_snake_dict(e.response)) @@ -347,7 +342,7 @@ def main(): try: versions = iam.list_policy_versions(PolicyArn=p['Arn'])['Versions'] except botocore.exceptions.ClientError as e: - module.fail_json(msg="Couldn't list policy versions: %s" % str(e), + module.fail_json(msg="Couldn't list policy versions: %s" % to_native(e), exception=traceback.format_exc(), **camel_dict_to_snake_dict(e.response)) for v in versions: @@ -355,14 +350,15 @@ def main(): try: iam.delete_policy_version(PolicyArn=p['Arn'], VersionId=v['VersionId']) except botocore.exceptions.ClientError as e: - module.fail_json(msg="Couldn't delete policy version %s: %s" % (v['VersionId'], str(e)), + module.fail_json(msg="Couldn't delete policy version %s: %s" % + (v['VersionId'], to_native(e)), exception=traceback.format_exc(), **camel_dict_to_snake_dict(e.response)) # Delete policy try: iam.delete_policy(PolicyArn=p['Arn']) - except: - module.fail_json(msg="Couldn't delete policy %s: %s" % (p['PolicyName'], str(e)), + except Exception as e: + module.fail_json(msg="Couldn't delete policy %s: %s" % (p['PolicyName'], to_native(e)), exception=traceback.format_exc(), **camel_dict_to_snake_dict(e.response)) # This is the one case where we will return the old policy @@ -372,6 +368,5 @@ def main(): # end main -# import module snippets if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/amazon/iam_mfa_device_facts.py b/lib/ansible/modules/cloud/amazon/iam_mfa_device_facts.py index 80f535a93d..57e9c466f3 100644 --- a/lib/ansible/modules/cloud/amazon/iam_mfa_device_facts.py +++ b/lib/ansible/modules/cloud/amazon/iam_mfa_device_facts.py @@ -1,18 +1,10 @@ #!/usr/bin/python -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -77,6 +69,10 @@ try: except ImportError: HAS_BOTO3 = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.ec2 import (HAS_BOTO3, boto3_conn, camel_dict_to_snake_dict, ec2_argument_spec, + get_aws_connection_info) + def list_mfa_devices(connection, module): user_name = module.params.get('user_name') @@ -115,9 +111,5 @@ def main(): list_mfa_devices(connection, module) -# import module snippets -from ansible.module_utils.basic import * -from ansible.module_utils.ec2 import * - if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/amazon/lambda_alias.py b/lib/ansible/modules/cloud/amazon/lambda_alias.py index 1d2fcaf3af..23fd6ed125 100644 --- a/lib/ansible/modules/cloud/amazon/lambda_alias.py +++ b/lib/ansible/modules/cloud/amazon/lambda_alias.py @@ -1,18 +1,10 @@ #!/usr/bin/python -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -147,6 +139,8 @@ name: sample: dev ''' +import re + try: import boto3 from botocore.exceptions import ClientError, ParamValidationError, MissingParametersError @@ -154,16 +148,20 @@ try: except ImportError: HAS_BOTO3 = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.ec2 import (HAS_BOTO3, boto3_conn, camel_dict_to_snake_dict, ec2_argument_spec, + get_aws_connection_info) + class AWSConnection: """ Create the connection object and client objects as required. """ - def __init__(self, ansible_obj, resources, boto3=True): + def __init__(self, ansible_obj, resources, boto3_=True): try: - self.region, self.endpoint, aws_connect_kwargs = get_aws_connection_info(ansible_obj, boto3=boto3) + self.region, self.endpoint, aws_connect_kwargs = get_aws_connection_info(ansible_obj, boto3=boto3_) self.resource_client = dict() if not resources: @@ -381,9 +379,5 @@ def main(): module.exit_json(**camel_dict_to_snake_dict(results)) -# ansible import module(s) kept at ~eof as recommended -from ansible.module_utils.basic import * -from ansible.module_utils.ec2 import * - if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/amazon/lambda_event.py b/lib/ansible/modules/cloud/amazon/lambda_event.py index ece7eb0be9..b3ca29b0d6 100644 --- a/lib/ansible/modules/cloud/amazon/lambda_event.py +++ b/lib/ansible/modules/cloud/amazon/lambda_event.py @@ -1,18 +1,10 @@ #!/usr/bin/python # (c) 2016, Pierre Jodouin -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -110,6 +102,7 @@ lambda_stream_events: type: list ''' +import re import sys try: @@ -119,6 +112,10 @@ try: except ImportError: HAS_BOTO3 = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.ec2 import (HAS_BOTO3, boto3_conn, camel_dict_to_snake_dict, ec2_argument_spec, + get_aws_connection_info) + # --------------------------------------------------------------------------------------------------- # @@ -423,9 +420,5 @@ def main(): module.exit_json(**results) -# ansible import module(s) kept at ~eof as recommended -from ansible.module_utils.basic import * -from ansible.module_utils.ec2 import * - if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/amazon/lightsail.py b/lib/ansible/modules/cloud/amazon/lightsail.py index 1023ee6329..924e0f7e8a 100644 --- a/lib/ansible/modules/cloud/amazon/lightsail.py +++ b/lib/ansible/modules/cloud/amazon/lightsail.py @@ -1,20 +1,12 @@ #!/usr/bin/python # -*- coding: utf-8 -*- -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + + ANSIBLE_METADATA = {'status': ['preview'], 'supported_by': 'community', 'metadata_version': '1.0'} @@ -163,7 +155,6 @@ instance: username: "ubuntu" ''' -import os import time import traceback @@ -180,7 +171,8 @@ except ImportError: pass from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.ec2 import ec2_argument_spec, get_aws_connection_info, boto3_conn, HAS_BOTO3, camel_dict_to_snake_dict +from ansible.module_utils.ec2 import (ec2_argument_spec, get_aws_connection_info, boto3_conn, + HAS_BOTO3, camel_dict_to_snake_dict) def create_instance(module, client, instance_name): diff --git a/lib/ansible/modules/cloud/amazon/rds_subnet_group.py b/lib/ansible/modules/cloud/amazon/rds_subnet_group.py index 09ca926e7f..b44559344f 100644 --- a/lib/ansible/modules/cloud/amazon/rds_subnet_group.py +++ b/lib/ansible/modules/cloud/amazon/rds_subnet_group.py @@ -1,18 +1,10 @@ #!/usr/bin/python -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['stableinterface'], @@ -81,6 +73,9 @@ try: except ImportError: HAS_BOTO = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.ec2 import HAS_BOTO, connect_to_aws, ec2_argument_spec, get_aws_connection_info + def main(): argument_spec = ec2_argument_spec() @@ -118,7 +113,7 @@ def main(): try: conn = connect_to_aws(boto.rds, region, **aws_connect_kwargs) - except boto.exception.BotoServerError as e: + except BotoServerError as e: module.fail_json(msg = e.error_message) try: @@ -154,9 +149,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() diff --git a/lib/ansible/modules/cloud/amazon/redshift_facts.py b/lib/ansible/modules/cloud/amazon/redshift_facts.py index 8a96eb957c..955da7cb71 100644 --- a/lib/ansible/modules/cloud/amazon/redshift_facts.py +++ b/lib/ansible/modules/cloud/amazon/redshift_facts.py @@ -1,20 +1,11 @@ #!/usr/bin/python # -*- coding: utf-8 -*- +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type -# This file is part of Ansible -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . ANSIBLE_METADATA = {'status': ['preview'], 'supported_by': 'community', @@ -284,18 +275,18 @@ iam_roles: sample: [] ''' -import traceback import re -# Import module snippets -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.ec2 import ec2_argument_spec, boto3_conn, get_aws_connection_info -from ansible.module_utils.ec2 import HAS_BOTO3, camel_dict_to_snake_dict +import traceback try: from botocore.exception import ClientError except ImportError: pass # will be picked up from imported HAS_BOTO3 +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.ec2 import ec2_argument_spec, boto3_conn, get_aws_connection_info +from ansible.module_utils.ec2 import HAS_BOTO3, camel_dict_to_snake_dict + def match_tags(tags_to_match, cluster): for key, value in tags_to_match.items(): diff --git a/lib/ansible/modules/cloud/amazon/redshift_subnet_group.py b/lib/ansible/modules/cloud/amazon/redshift_subnet_group.py index 83c58aab2c..336d3a9e06 100644 --- a/lib/ansible/modules/cloud/amazon/redshift_subnet_group.py +++ b/lib/ansible/modules/cloud/amazon/redshift_subnet_group.py @@ -1,19 +1,11 @@ #!/usr/bin/python # Copyright 2014 Jens Carl, Hothead Games Inc. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -98,6 +90,9 @@ try: except ImportError: HAS_BOTO = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.ec2 import HAS_BOTO, connect_to_aws, ec2_argument_spec, get_aws_connection_info + def main(): argument_spec = ec2_argument_spec() @@ -179,9 +174,6 @@ def main(): module.exit_json(changed=changed, group=group) -# import module snippets -from ansible.module_utils.basic import * -from ansible.module_utils.ec2 import * if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/amazon/route53.py b/lib/ansible/modules/cloud/amazon/route53.py index 59cf9366e3..15ef89d327 100644 --- a/lib/ansible/modules/cloud/amazon/route53.py +++ b/lib/ansible/modules/cloud/amazon/route53.py @@ -1,18 +1,10 @@ #!/usr/bin/python -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['stableinterface'], @@ -302,17 +294,9 @@ EXAMPLES = ''' ''' -MINIMUM_BOTO_VERSION = '2.28.0' -WAIT_RETRY_SLEEP = 5 # how many seconds to wait between propagation status polls - - import time import distutils.version -# import module snippets -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.ec2 import ec2_argument_spec, get_aws_connection_info - try: import boto import boto.ec2 @@ -324,6 +308,13 @@ try: except ImportError: HAS_BOTO = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.ec2 import ec2_argument_spec, get_aws_connection_info + + +MINIMUM_BOTO_VERSION = '2.28.0' +WAIT_RETRY_SLEEP = 5 # how many seconds to wait between propagation status polls + class TimeoutError(Exception): pass @@ -613,5 +604,6 @@ def main(): module.exit_json(changed=True) + if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/amazon/route53_facts.py b/lib/ansible/modules/cloud/amazon/route53_facts.py index 5906e1f79d..913ae48433 100644 --- a/lib/ansible/modules/cloud/amazon/route53_facts.py +++ b/lib/ansible/modules/cloud/amazon/route53_facts.py @@ -1,18 +1,10 @@ #!/usr/bin/python -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], diff --git a/lib/ansible/modules/cloud/amazon/s3_lifecycle.py b/lib/ansible/modules/cloud/amazon/s3_lifecycle.py index b7c36b7a7f..6ea905c6e8 100644 --- a/lib/ansible/modules/cloud/amazon/s3_lifecycle.py +++ b/lib/ansible/modules/cloud/amazon/s3_lifecycle.py @@ -1,17 +1,10 @@ #!/usr/bin/python -# -# This is a free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This Ansible library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this library. If not, see . +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['stableinterface'], @@ -165,7 +158,7 @@ try: import boto.ec2 from boto.s3.connection import OrdinaryCallingFormat, Location from boto.s3.lifecycle import Lifecycle, Rule, Expiration, Transition - from boto.exception import BotoServerError, S3CreateError, S3ResponseError + from boto.exception import BotoServerError, S3ResponseError HAS_BOTO = True except ImportError: HAS_BOTO = False @@ -173,6 +166,7 @@ except ImportError: from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.ec2 import AnsibleAWSError, ec2_argument_spec, get_aws_connection_info + def create_lifecycle_rule(connection, module): name = module.params.get("name") diff --git a/lib/ansible/modules/cloud/amazon/s3_logging.py b/lib/ansible/modules/cloud/amazon/s3_logging.py index b4b30f9afb..fc26066c2b 100644 --- a/lib/ansible/modules/cloud/amazon/s3_logging.py +++ b/lib/ansible/modules/cloud/amazon/s3_logging.py @@ -1,17 +1,10 @@ #!/usr/bin/python -# -# This is a free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This Ansible library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this library. If not, see . +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['stableinterface'], @@ -72,7 +65,7 @@ EXAMPLES = ''' try: import boto.ec2 from boto.s3.connection import OrdinaryCallingFormat, Location - from boto.exception import BotoServerError, S3CreateError, S3ResponseError + from boto.exception import S3ResponseError HAS_BOTO = True except ImportError: HAS_BOTO = False diff --git a/lib/ansible/modules/cloud/amazon/s3_website.py b/lib/ansible/modules/cloud/amazon/s3_website.py index a4ca543573..84b8961c8f 100644 --- a/lib/ansible/modules/cloud/amazon/s3_website.py +++ b/lib/ansible/modules/cloud/amazon/s3_website.py @@ -1,17 +1,10 @@ #!/usr/bin/python -# -# This is a free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This Ansible library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this library. If not, see . +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], @@ -153,12 +146,17 @@ routing_rules: import time try: - from botocore.exceptions import ClientError, ParamValidationError, NoCredentialsError import boto3 + from botocore.exceptions import ClientError, ParamValidationError HAS_BOTO3 = True except ImportError: HAS_BOTO3 = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.ec2 import (HAS_BOTO3, boto3_conn, camel_dict_to_snake_dict, ec2_argument_spec, + get_aws_connection_info) + + def _create_redirect_dict(url): redirect_dict = {} @@ -313,8 +311,5 @@ def main(): disable_bucket_as_website(client_connection, module) -from ansible.module_utils.basic import * -from ansible.module_utils.ec2 import * - if __name__ == '__main__': main() diff --git a/lib/ansible/modules/cloud/amazon/sns.py b/lib/ansible/modules/cloud/amazon/sns.py index 65c8197e77..4a91a7143a 100644 --- a/lib/ansible/modules/cloud/amazon/sns.py +++ b/lib/ansible/modules/cloud/amazon/sns.py @@ -2,21 +2,11 @@ # -*- coding: utf-8 -*- # (c) 2014, Michael J. Schultz -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], diff --git a/lib/ansible/modules/cloud/amazon/sns_topic.py b/lib/ansible/modules/cloud/amazon/sns_topic.py index 0a00e90c0b..9d8e3a3b49 100644 --- a/lib/ansible/modules/cloud/amazon/sns_topic.py +++ b/lib/ansible/modules/cloud/amazon/sns_topic.py @@ -1,18 +1,10 @@ #!/usr/bin/python # -*- coding: utf-8 -*- -# -# This is a free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This Ansible library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this library. If not, see . +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type ANSIBLE_METADATA = {'metadata_version': '1.0', @@ -129,9 +121,9 @@ sns_topic: attributes_set: [] ''' -import time import json import re +import time try: import boto.sns diff --git a/lib/ansible/modules/cloud/amazon/sqs_queue.py b/lib/ansible/modules/cloud/amazon/sqs_queue.py index d23d575f7c..8622239f09 100644 --- a/lib/ansible/modules/cloud/amazon/sqs_queue.py +++ b/lib/ansible/modules/cloud/amazon/sqs_queue.py @@ -1,18 +1,10 @@ #!/usr/bin/python -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['stableinterface'], diff --git a/lib/ansible/modules/cloud/amazon/sts_assume_role.py b/lib/ansible/modules/cloud/amazon/sts_assume_role.py index e0b8fd7459..fcbe681387 100644 --- a/lib/ansible/modules/cloud/amazon/sts_assume_role.py +++ b/lib/ansible/modules/cloud/amazon/sts_assume_role.py @@ -1,18 +1,10 @@ #!/usr/bin/python -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['stableinterface'], diff --git a/lib/ansible/modules/cloud/amazon/sts_session_token.py b/lib/ansible/modules/cloud/amazon/sts_session_token.py index af2c652ab2..539296a4d2 100644 --- a/lib/ansible/modules/cloud/amazon/sts_session_token.py +++ b/lib/ansible/modules/cloud/amazon/sts_session_token.py @@ -1,18 +1,10 @@ #!/usr/bin/python -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['stableinterface'],