Skip to content

Commit

Permalink
Bulk migration to AnsibleAWSModule (ansible-collections#173)
Browse files Browse the repository at this point in the history
* Update comments to reference AnsibleAWSModule rather than AnsibleModule
* Bulk re-order imports and split onto one from import per-line.
* Add AnsibleAWSModule imports
* Migrate boto 2 based modules to AnsibleAWSModule
* Move boto3-only modules over to AnsibleAWSModule
* Remove extra ec2_argument_spec calls - not needed now we're using AnsibleAWSModule
* Remove most HAS_BOTO3 code, it's handled by AnsibleAWSModule
* Handle missing Boto 2 consistently  (HAS_BOTO)
* Remove AnsibleModule imports
* Changelog fragment
  • Loading branch information
tremble authored and jillr committed May 10, 2021
1 parent 3e9f0b6 commit 54c895e
Showing 1 changed file with 17 additions and 25 deletions.
42 changes: 17 additions & 25 deletions plugins/modules/ec2_instance_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,18 +496,15 @@
try:
import boto3
from botocore.exceptions import ClientError
HAS_BOTO3 = True
except ImportError:
HAS_BOTO3 = False
pass # Handled by AnsibleAWSModule

from ansible.module_utils.basic import AnsibleModule
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import (ansible_dict_to_boto3_filter_list,
boto3_conn,
boto3_tag_list_to_ansible_dict,
camel_dict_to_snake_dict,
ec2_argument_spec,
get_aws_connection_info,
)
from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ansible_dict_to_boto3_filter_list
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import boto3_conn
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import boto3_tag_list_to_ansible_dict
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import get_aws_connection_info


def list_ec2_instances(connection, module):
Expand Down Expand Up @@ -538,26 +535,21 @@ def list_ec2_instances(connection, module):

def main():

argument_spec = ec2_argument_spec()
argument_spec.update(
dict(
instance_ids=dict(default=[], type='list', elements='str'),
filters=dict(default={}, type='dict')
)
argument_spec = dict(
instance_ids=dict(default=[], type='list', elements='str'),
filters=dict(default={}, type='dict')
)

module = AnsibleModule(argument_spec=argument_spec,
mutually_exclusive=[
['instance_ids', 'filters']
],
supports_check_mode=True
)
module = AnsibleAWSModule(
argument_spec=argument_spec,
mutually_exclusive=[
['instance_ids', 'filters']
],
supports_check_mode=True,
)
if module._name == 'ec2_instance_facts':
module.deprecate("The 'ec2_instance_facts' module has been renamed to 'ec2_instance_info'", date='2021-12-01', collection_name='community.aws')

if not HAS_BOTO3:
module.fail_json(msg='boto3 required for this module')

region, ec2_url, aws_connect_params = get_aws_connection_info(module, boto3=True)

if region:
Expand Down

0 comments on commit 54c895e

Please sign in to comment.