1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Add option to toggle describe_image_attribute lookups (#34977)

This commit is contained in:
Prasad Katti 2018-01-17 16:20:10 -08:00 committed by Will Thames
parent 20824b8f3d
commit 5a9562a101

View file

@ -35,6 +35,11 @@ options:
description:
- Filter images by users with explicit launch permissions. Valid options are an AWS account ID, self, or all (public AMIs).
aliases: [executable_user]
describe_image_attributes:
description:
- Describe attributes (like launchPermission) of the images found.
default: no
choices: ["yes", "no"]
extends_documentation_fragment:
- aws
@ -127,7 +132,7 @@ images:
sample: machine
launch_permissions:
description: launch permissions of the ami
returned: when image is owned by calling account
returned: when image is owned by calling account and describe_image_attributes is yes
type: complex
sample: [{"group": "all"}, {"user_id": "408466080000"}]
name:
@ -222,6 +227,7 @@ def list_ec2_images(ec2_client, module):
for image in images:
try:
image['tags'] = boto3_tag_list_to_ansible_dict(image.get('tags', []))
if module.params.get("describe_image_attributes"):
launch_permissions = ec2_client.describe_image_attribute(Attribute='launchPermission', ImageId=image['image_id'])['LaunchPermissions']
image['launch_permissions'] = [camel_dict_to_snake_dict(perm) for perm in launch_permissions]
except (ClientError, BotoCoreError) as err:
@ -239,7 +245,8 @@ def main():
image_ids=dict(default=[], type='list', aliases=['image_id']),
filters=dict(default={}, type='dict'),
owners=dict(default=[], type='list', aliases=['owner']),
executable_users=dict(default=[], type='list', aliases=['executable_user'])
executable_users=dict(default=[], type='list', aliases=['executable_user']),
describe_image_attributes=dict(default=False, type='bool')
)
)