ec2_ami_find - Searches for AMIs to obtain the AMI ID and other information¶
New in version 2.0.
DEPRECATED¶
Removed in Ansible: | |
---|---|
version: 2.9 | |
Why: | Various AWS modules have been combined and replaced with ec2_ami_facts. |
Alternative: | Use ec2_ami_facts instead. |
Synopsis¶
- 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
Requirements¶
The below requirements are needed on the host that executes this module.
- boto
- python >= 2.6
Parameters¶
Parameter | Choices/Defaults | Comments |
---|---|---|
ami_id |
An AMI ID to match.
|
|
ami_tags |
A hash/dictionary of tags to match for the AMI.
|
|
architecture |
An architecture type to match (e.g. x86_64).
|
|
aws_access_key |
AWS access key. If not set then the value of the AWS_ACCESS_KEY_ID, AWS_ACCESS_KEY or EC2_ACCESS_KEY environment variable is used.
aliases: ec2_access_key, access_key |
|
aws_secret_key |
AWS secret key. If not set then the value of the AWS_SECRET_ACCESS_KEY, AWS_SECRET_KEY, or EC2_SECRET_KEY environment variable is used.
aliases: ec2_secret_key, secret_key |
|
ec2_url |
Url to use to connect to EC2 or your Eucalyptus cloud (by default the module will use EC2 endpoints). Ignored for modules where region is required. Must be specified for all other modules if region is not used. If not set then the value of the EC2_URL environment variable, if any, is used.
|
|
hypervisor |
A hypervisor type type to match (e.g. xen).
|
|
is_public
bool |
|
Whether or not the image(s) are public.
|
name |
An AMI name to match.
|
|
no_result_action |
|
What to do when no results are found.
'success' reports success and returns an empty array
'fail' causes the module to report failure
|
owner |
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?\.
|
|
platform |
Platform type to match.
|
|
product_code
(added in 2.3) |
Marketplace product code to match.
|
|
profile
(added in 1.6) |
Uses a boto profile. Only works with boto >= 2.24.0.
|
|
region
required |
The AWS region to use.
aliases: aws_region, ec2_region |
|
root_device_type
(added in 2.5) |
Root device type to match (e.g. ebs, instance-store).
|
|
security_token
(added in 1.6) |
AWS STS security token. If not set then the value of the AWS_SECURITY_TOKEN or EC2_SECURITY_TOKEN environment variable is used.
aliases: access_token |
|
sort |
|
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.
|
sort_end |
Which result to end with (when sorting).
Corresponds to Python slice notation.
|
|
sort_order |
|
Order in which to sort results.
Only used when the 'sort' parameter is specified.
|
sort_start |
Which result to start with (when sorting).
Corresponds to Python slice notation.
|
|
sort_tag |
Tag name with which to sort results.
Required when specifying 'sort=tag'.
|
|
state |
Default: available
|
AMI state to match.
|
validate_certs
bool (added in 1.5) |
|
When set to "no", SSL certificates will not be validated for boto versions >= 2.6.0.
|
virtualization_type |
Virtualization type to match (e.g. hvm).
|
Notes¶
Note
- This module is not backwards compatible with the previous version of the ec2_search_ami module which worked only for Ubuntu AMIs listed on cloud-images.ubuntu.com.
- See the example below for a suggestion of how to search by distro/release.
- If parameters are not set within the module, the following environment variables can be used in decreasing order of precedence
AWS_URL
orEC2_URL
,AWS_ACCESS_KEY_ID
orAWS_ACCESS_KEY
orEC2_ACCESS_KEY
,AWS_SECRET_ACCESS_KEY
orAWS_SECRET_KEY
orEC2_SECRET_KEY
,AWS_SECURITY_TOKEN
orEC2_SECURITY_TOKEN
,AWS_REGION
orEC2_REGION
- Ansible uses the boto configuration file (typically ~/.boto) if no credentials are provided. See https://boto.readthedocs.io/en/latest/boto_config_tut.html
AWS_REGION
orEC2_REGION
can be typically be used to specify the AWS region, when required, but this can also be configured in the boto config file
Examples¶
# 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
Return Values¶
Common return values are documented here, the following are the fields unique to this module:
Key | Returned | Description |
---|---|---|
ami_id
string
|
when AMI found |
id of found amazon image
Sample:
ami-e9095e8c
|
architecture
string
|
when AMI found |
architecture of image
Sample:
x86_64
|
block_device_mapping
dict
|
when AMI found |
block device mapping associated with image
Sample:
{ '/dev/xvda': { 'delete_on_termination': true, 'encrypted': false, 'size': 8, 'snapshot_id': 'snap-ca0330b8', 'volume_type': 'gp2' }
|
creationDate
string
|
when AMI found |
creation date of image
Sample:
2015-10-15T22:43:44.000Z
|
description
string
|
when AMI found |
description of image
Sample:
test-server01
|
hypervisor
string
|
when AMI found |
type of hypervisor
Sample:
xen
|
is_public
bool
|
when AMI found |
whether image is public
|
location
string
|
when AMI found |
location of image
Sample:
435210894375/test-server01-20151015-234343
|
name
string
|
when AMI found |
ami name of image
Sample:
test-server01-20151015-234343
|
owner_id
string
|
when AMI found |
owner of image
Sample:
435210894375
|
platform
string
|
when AMI found |
platform of image
|
root_device_name
string
|
when AMI found |
root device name of image
Sample:
/dev/xvda
|
root_device_type
string
|
when AMI found |
root device type of image
Sample:
ebs
|
state
string
|
when AMI found |
state of image
Sample:
available
|
tags
dict
|
when AMI found |
tags assigned to image
Sample:
{ 'Environment': 'devel', 'Name': 'test-server01', 'Role': 'web' }
|
virtualization_type
string
|
when AMI found |
image virtualization type
Sample:
hvm
|
Status¶
This module is flagged as deprecated and will be removed in version 2.9. For more information see DEPRECATED.
Author¶
- Tom Bamford (@tombamford)
Hint
If you notice any issues in this documentation you can edit this document to improve it.