ansible.builtin.ec2_ami (v2.7.16) — module

create or destroy an image in ec2

| "added in version" 1.3 of ansible.builtin"

Authors: Evan Duffield (@scicoin-project) <eduffield@iacquire.com>, Constantin Bugneac (@Constantin07) <constantin.bugneac@endava.com>, Ross Williams (@gunzy83) <gunzy83au@gmail.com>, Willem van Ketwich (@wilvk) <willvk@gmail.com>

stableinterface | supported by certified

Install Ansible via pip

Install with pip install ansible==2.7.16

Description

Registers or deregisters ec2 images.

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Note: These examples do not set authentication details, see the AWS Guide for details.

# Basic AMI Creation
- ec2_ami:
    instance_id: i-xxxxxx
    wait: yes
    name: newtest
    tags:
      Name: newtest
      Service: TestService
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Basic AMI Creation, without waiting
- ec2_ami:
    instance_id: i-xxxxxx
    wait: no
    name: newtest
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# AMI Registration from EBS Snapshot
- ec2_ami:
    name: newtest
    state: present
    architecture: x86_64
    virtualization_type: hvm
    root_device_name: /dev/xvda
    device_mapping:
      - device_name: /dev/xvda
        volume_size: 8
        snapshot_id: snap-xxxxxxxx
        delete_on_termination: true
        volume_type: gp2
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# AMI Creation, with a custom root-device size and another EBS attached
- ec2_ami:
    instance_id: i-xxxxxx
    name: newtest
    device_mapping:
        - device_name: /dev/sda1
          size: XXX
          delete_on_termination: true
          volume_type: gp2
        - device_name: /dev/sdb
          size: YYY
          delete_on_termination: false
          volume_type: gp2
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# AMI Creation, excluding a volume attached at /dev/sdb
- ec2_ami:
    instance_id: i-xxxxxx
    name: newtest
    device_mapping:
        - device_name: /dev/sda1
          size: XXX
          delete_on_termination: true
          volume_type: gp2
        - device_name: /dev/sdb
          no_device: yes
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Deregister/Delete AMI (keep associated snapshots)
- ec2_ami:
    image_id: "{{ instance.image_id }}"
    delete_snapshot: False
    state: absent
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Deregister AMI (delete associated snapshots too)
- ec2_ami:
    image_id: "{{ instance.image_id }}"
    delete_snapshot: True
    state: absent
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Update AMI Launch Permissions, making it public
- ec2_ami:
    image_id: "{{ instance.image_id }}"
    state: present
    launch_permissions:
      group_names: ['all']
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Allow AMI to be launched by another account
- ec2_ami:
    image_id: "{{ instance.image_id }}"
    state: present
    launch_permissions:
      user_ids: ['123456789012']

Inputs

    
name:
    description:
    - The name of the new AMI.

tags:
    description:
    - A dictionary of tags to add to the new image; '{"key":"value"}' and '{"key":"value","key":"value"}'
    version_added: '2.0'
    version_added_collection: ansible.builtin

wait:
    default: 'no'
    description:
    - Wait for the AMI to be in state 'available' before returning.
    type: bool

state:
    choices:
    - absent
    - present
    default: present
    description:
    - Register or deregister an AMI.

region:
    aliases:
    - aws_region
    - ec2_region
    description:
    - The AWS region to use.
    - For global services such as IAM, Route53 and CloudFront, I(region) is ignored.
    - The C(AWS_REGION) or C(EC2_REGION) environment variables may also be used.
    - See the Amazon AWS documentation for more information U(http://docs.aws.amazon.com/general/latest/gr/rande.html#ec2_region).
    - The C(ec2_region) alias has been deprecated and will be removed in a release after
      2024-12-01
    - Support for the C(EC2_REGION) environment variable has been deprecated and will
      be removed in a release after 2024-12-01.
    type: str

profile:
    aliases:
    - aws_profile
    description:
    - A named AWS profile to use for authentication.
    - See the AWS documentation for more information about named profiles U(https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html).
    - The C(AWS_PROFILE) environment variable may also be used.
    - The I(profile) option is mutually exclusive with the I(aws_access_key), I(aws_secret_key)
      and I(security_token) options.
    type: str

image_id:
    description:
    - Image ID to be deregistered.

kernel_id:
    description:
    - The target kernel id of the image to register.
    version_added: '2.3'
    version_added_collection: ansible.builtin

no_reboot:
    default: false
    description:
    - Flag indicating that the bundling process should not attempt to shutdown the instance
      before bundling. If this flag is True, the responsibility of maintaining file system
      integrity is left to the owner of the instance.
    type: bool

access_key:
    aliases:
    - aws_access_key_id
    - aws_access_key
    - ec2_access_key
    description:
    - AWS access key ID.
    - See the AWS documentation for more information about access tokens U(https://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-secret-access-keys).
    - The C(AWS_ACCESS_KEY_ID), C(AWS_ACCESS_KEY) or C(EC2_ACCESS_KEY) environment variables
      may also be used in decreasing order of preference.
    - The I(aws_access_key) and I(profile) options are mutually exclusive.
    - The I(aws_access_key_id) alias was added in release 5.1.0 for consistency with the
      AWS botocore SDK.
    - The I(ec2_access_key) alias has been deprecated and will be removed in a release
      after 2024-12-01.
    - Support for the C(EC2_ACCESS_KEY) environment variable has been deprecated and will
      be removed in a release after 2024-12-01.
    type: str

aws_config:
    description:
    - A dictionary to modify the botocore configuration.
    - Parameters can be found in the AWS documentation U(https://botocore.amazonaws.com/v1/documentation/api/latest/reference/config.html#botocore.config.Config).
    type: dict

purge_tags:
    default: 'no'
    description: Whether to remove existing tags that aren't passed in the C(tags) parameter
    version_added: '2.5'
    version_added_collection: ansible.builtin

ramdisk_id:
    description:
    - The ID of the RAM disk.
    version_added: '2.5'
    version_added_collection: ansible.builtin

secret_key:
    aliases:
    - aws_secret_access_key
    - aws_secret_key
    - ec2_secret_key
    description:
    - AWS secret access key.
    - See the AWS documentation for more information about access tokens U(https://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-secret-access-keys).
    - The C(AWS_SECRET_ACCESS_KEY), C(AWS_SECRET_KEY), or C(EC2_SECRET_KEY) environment
      variables may also be used in decreasing order of preference.
    - The I(secret_key) and I(profile) options are mutually exclusive.
    - The I(aws_secret_access_key) alias was added in release 5.1.0 for consistency with
      the AWS botocore SDK.
    - The I(ec2_secret_key) alias has been deprecated and will be removed in a release
      after 2024-12-01.
    - Support for the C(EC2_SECRET_KEY) environment variable has been deprecated and will
      be removed in a release after 2024-12-01.
    type: str

description:
    description:
    - Human-readable string describing the contents and purpose of the AMI.

instance_id:
    description:
    - Instance ID to create the AMI from.

architecture:
    description:
    - The target architecture of the image to register
    version_added: '2.3'
    version_added_collection: ansible.builtin

endpoint_url:
    aliases:
    - ec2_url
    - aws_endpoint_url
    - s3_url
    description:
    - URL to connect to instead of the default AWS endpoints.  While this can be used
      to connection to other AWS-compatible services the amazon.aws and community.aws
      collections are only tested against AWS.
    - The  C(AWS_URL) or C(EC2_URL) environment variables may also be used, in decreasing
      order of preference.
    - The I(ec2_url) and I(s3_url) aliases have been deprecated and will be removed in
      a release after 2024-12-01.
    - Support for the C(EC2_URL) environment variable has been deprecated and will be
      removed in a release after 2024-12-01.
    type: str

wait_timeout:
    default: 900
    description:
    - How long before wait gives up, in seconds.

aws_ca_bundle:
    description:
    - The location of a CA Bundle to use when validating SSL certificates.
    - The C(AWS_CA_BUNDLE) environment variable may also be used.
    type: path

session_token:
    aliases:
    - aws_session_token
    - security_token
    - aws_security_token
    - access_token
    description:
    - AWS STS session token for use with temporary credentials.
    - See the AWS documentation for more information about access tokens U(https://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-secret-access-keys).
    - The C(AWS_SESSION_TOKEN), C(AWS_SECURITY_TOKEN) or C(EC2_SECURITY_TOKEN) environment
      variables may also be used in decreasing order of preference.
    - The I(security_token) and I(profile) options are mutually exclusive.
    - Aliases I(aws_session_token) and I(session_token) were added in release 3.2.0, with
      the parameter being renamed from I(security_token) to I(session_token) in release
      6.0.0.
    - The I(security_token), I(aws_security_token), and I(access_token) aliases have been
      deprecated and will be removed in a release after 2024-12-01.
    - Support for the C(EC2_SECRET_KEY) and C(AWS_SECURITY_TOKEN) environment variables
      has been deprecated and will be removed in a release after 2024-12-01.
    type: str

device_mapping:
    description:
    - List of device hashes/dictionaries with custom configurations (same block-device-mapping
      parameters).
    - 'Valid properties include: device_name, volume_type, size/volume_size (in GB), delete_on_termination
      (boolean), no_device (boolean), snapshot_id, iops (for io1 volume_type), encrypted

      '
    version_added: '2.0'
    version_added_collection: ansible.builtin

image_location:
    description:
    - The s3 location of an image to use for the AMI.
    version_added: '2.5'
    version_added_collection: ansible.builtin

validate_certs:
    default: true
    description:
    - When set to C(false), SSL certificates will not be validated for communication with
      the AWS APIs.
    - Setting I(validate_certs=false) is strongly discouraged, as an alternative, consider
      setting I(aws_ca_bundle) instead.
    type: bool

delete_snapshot:
    default: 'no'
    description:
    - Delete snapshots when deregistering the AMI.
    type: bool

billing_products:
    description:
    - A list of valid billing codes. To be used with valid accounts by aws marketplace
      vendors.
    version_added: '2.5'
    version_added_collection: ansible.builtin

root_device_name:
    description:
    - The root device name of the image to register.
    version_added: '2.3'
    version_added_collection: ansible.builtin

sriov_net_support:
    description:
    - Set to simple to enable enhanced networking with the Intel 82599 Virtual Function
      interface for the AMI and any instances that you launch from the AMI.
    version_added: '2.5'
    version_added_collection: ansible.builtin

launch_permissions:
    description:
    - Users and groups that should be able to launch the AMI. Expects dictionary with
      a key of user_ids and/or group_names. user_ids should be a list of account ids.
      group_name should be a list of groups, "all" is the only acceptable value currently.
    - You must pass all desired launch permissions if you wish to modify existing launch
      permissions (passing just groups will remove all users)
    version_added: '2.0'
    version_added_collection: ansible.builtin

enhanced_networking:
    description:
    - A boolean representing whether enhanced networking with ENA is enabled or not.
    version_added: '2.5'
    version_added_collection: ansible.builtin

virtualization_type:
    description:
    - The virtualization type of the image to register.
    version_added: '2.3'
    version_added_collection: ansible.builtin

debug_botocore_endpoint_logs:
    default: false
    description:
    - Use a C(botocore.endpoint) logger to parse the unique (rather than total) C("resource:action")
      API calls made during a task, outputing the set to the resource_actions key in the
      task results. Use the C(aws_resource_action) callback to output to total list made
      during a playbook.
    - The C(ANSIBLE_DEBUG_BOTOCORE_LOGS) environment variable may also be used.
    type: bool

Outputs

architecture:
  description: architecture of image
  returned: when AMI is created or already exists
  sample: x86_64
  type: string
block_device_mapping:
  description: block device mapping associated with image
  returned: when AMI is created or already exists
  sample:
    /dev/sda1:
      delete_on_termination: true
      encrypted: false
      size: 10
      snapshot_id: snap-1a03b80e7
      volume_type: standard
  type: dict
creationDate:
  description: creation date of image
  returned: when AMI is created or already exists
  sample: '2015-10-15T22:43:44.000Z'
  type: string
description:
  description: description of image
  returned: when AMI is created or already exists
  sample: nat-server
  type: string
hypervisor:
  description: type of hypervisor
  returned: when AMI is created or already exists
  sample: xen
  type: string
image_id:
  description: id of the image
  returned: when AMI is created or already exists
  sample: ami-1234abcd
  type: string
is_public:
  description: whether image is public
  returned: when AMI is created or already exists
  sample: false
  type: bool
launch_permission:
  description: permissions allowing other accounts to access the AMI
  returned: when AMI is created or already exists
  sample:
  - group: all
  type: list
location:
  description: location of image
  returned: when AMI is created or already exists
  sample: 315210894379/nat-server
  type: string
name:
  description: ami name of image
  returned: when AMI is created or already exists
  sample: nat-server
  type: string
ownerId:
  description: owner of image
  returned: when AMI is created or already exists
  sample: '435210894375'
  type: string
platform:
  description: platform of image
  returned: when AMI is created or already exists
  sample: null
  type: string
root_device_name:
  description: root device name of image
  returned: when AMI is created or already exists
  sample: /dev/sda1
  type: string
root_device_type:
  description: root device type of image
  returned: when AMI is created or already exists
  sample: ebs
  type: string
snapshots_deleted:
  description: a list of snapshot ids deleted after deregistering image
  returned: after AMI is deregistered, if 'delete_snapshot' is set to 'yes'
  sample:
  - snap-fbcccb8f
  - snap-cfe7cdb4
  type: list
state:
  description: state of image
  returned: when AMI is created or already exists
  sample: available
  type: string
tags:
  description: a dictionary of tags assigned to image
  returned: when AMI is created or already exists
  sample:
    Env: devel
    Name: nat-server
  type: dict
virtualization_type:
  description: image virtualization type
  returned: when AMI is created or already exists
  sample: hvm
  type: string