ansible / ansible.builtin / v2.3.3.0-1 / module / ec2_ami_find Searches for AMIs to obtain the AMI ID and other information | "added in version" 2.0 of ansible.builtin" Authors: Tom Bamford (@tombamford) preview | supported by communityansible.builtin.ec2_ami_find (v2.3.3.0-1) — module
pip
Install with pip install ansible==2.3.3.0.post1
Returns list of matching AMIs with AMI ID, along with other useful information
Can search AMIs with different owners
Can search by matching tag(s), by AMI name and/or other criteria
Results can be sorted and sliced
# Note: These examples do not set authentication details, see the AWS Guide for details. # Search for the AMI tagged "project:website" - ec2_ami_find: owner: self ami_tags: project: website no_result_action: fail register: ami_find
# Search for the latest Ubuntu 14.04 AMI - ec2_ami_find: name: "ubuntu/images/ebs/ubuntu-trusty-14.04-amd64-server-*" owner: 099720109477 sort: name sort_order: descending sort_end: 1 register: ami_find
# Launch an EC2 instance - ec2: image: "{{ ami_find.results[0].ami_id }}" instance_type: m3.medium key_name: mykey wait: yes
name: default: null description: - An AMI name to match. required: false sort: choices: - name - description - tag - architecture - block_device_mapping - creationDate - hypervisor - is_public - location - owner_id - platform - root_device_name - root_device_type - state - virtualization_type default: null description: - Optional attribute which with to sort the results. - If specifying 'tag', the 'tag_name' parameter is required. - Starting at version 2.1, additional sort choices of architecture, block_device_mapping, creationDate, hypervisor, is_public, location, owner_id, platform, root_device_name, root_device_type, state, and virtualization_type are supported. required: false owner: default: null description: - Search AMIs owned by the specified owner - Can specify an AWS account ID, or one of the special IDs 'self', 'amazon' or 'aws-marketplace' - If not specified, all EC2 AMIs in the specified region will be searched. - You can include wildcards in many of the search options. An asterisk (*) matches zero or more characters, and a question mark (?) matches exactly one character. You can escape special characters using a backslash (\) before the character. For example, a value of \*amazon\?\ searches for the literal string *amazon?\. required: false state: default: available description: - AMI state to match. required: false ami_id: default: null description: - An AMI ID to match. required: false region: aliases: - aws_region - ec2_region description: - The AWS region to use. required: true ami_tags: default: null description: - A hash/dictionary of tags to match for the AMI. required: false platform: default: null description: - Platform type to match. required: false sort_end: default: null description: - Which result to end with (when sorting). - Corresponds to Python slice notation. required: false sort_tag: default: null description: - Tag name with which to sort results. - Required when specifying 'sort=tag'. required: false is_public: choices: - 'yes' - 'no' default: null description: - Whether or not the image(s) are public. required: false hypervisor: default: null description: - A hypervisor type type to match (e.g. xen). required: false sort_order: choices: - ascending - descending default: ascending description: - Order in which to sort results. - Only used when the 'sort' parameter is specified. required: false sort_start: default: null description: - Which result to start with (when sorting). - Corresponds to Python slice notation. required: false architecture: default: null description: - An architecture type to match (e.g. x86_64). required: false product_code: default: null description: - Marketplace product code to match. required: false version_added: '2.3' version_added_collection: ansible.builtin no_result_action: choices: - success - fail default: success description: - What to do when no results are found. - '''success'' reports success and returns an empty array' - '''fail'' causes the module to report failure' required: false virtualization_type: default: null description: - Virtualization type to match (e.g. hvm). required: false
ami_id: description: id of found amazon image returned: when AMI found sample: ami-e9095e8c type: string architecture: description: architecture of image returned: when AMI found sample: x86_64 type: string block_device_mapping: description: block device mapping associated with image returned: when AMI found sample: '{ ''/dev/xvda'': { ''delete_on_termination'': true, ''encrypted'': false, ''size'': 8, ''snapshot_id'': ''snap-ca0330b8'', ''volume_type'': ''gp2'' }' type: dictionary of block devices creationDate: description: creation date of image returned: when AMI found sample: '2015-10-15T22:43:44.000Z' type: string description: description: description of image returned: when AMI found sample: test-server01 type: string hypervisor: description: type of hypervisor returned: when AMI found sample: xen type: string is_public: description: whether image is public returned: when AMI found sample: false type: bool location: description: location of image returned: when AMI found sample: 435210894375/test-server01-20151015-234343 type: string name: description: ami name of image returned: when AMI found sample: test-server01-20151015-234343 type: string owner_id: description: owner of image returned: when AMI found sample: '435210894375' type: string platform: description: platform of image returned: when AMI found sample: null type: string root_device_name: description: rood device name of image returned: when AMI found sample: /dev/xvda type: string root_device_type: description: rood device type of image returned: when AMI found sample: ebs type: string state: description: state of image returned: when AMI found sample: available type: string tags: description: tags assigned to image returned: when AMI found sample: '{ ''Environment'': ''devel'', ''Name'': ''test-server01'', ''Role'': ''web'' }' type: dictionary of tags virtualization_type: description: image virtualization type returned: when AMI found sample: hvm type: string