ansible / ansible.builtin / v2.9.17 / module / ec2_ami 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 communityansible.builtin.ec2_ami (v2.9.17) — module
pip
Install with pip install ansible==2.9.17
Registers or deregisters ec2 images.
# 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
# Basic AMI Creation, without waiting - ec2_ami: instance_id: i-xxxxxx wait: no name: newtest
# 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
# 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
# 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
# Deregister/Delete AMI (keep associated snapshots) - ec2_ami: image_id: "{{ instance.image_id }}" delete_snapshot: False state: absent
# Deregister AMI (delete associated snapshots too) - ec2_ami: image_id: "{{ instance.image_id }}" delete_snapshot: True state: absent
# Update AMI Launch Permissions, making it public - ec2_ami: image_id: "{{ instance.image_id }}" state: present launch_permissions: group_names: ['all']
# Allow AMI to be launched by another account - ec2_ami: image_id: "{{ instance.image_id }}" state: present launch_permissions: user_ids: ['123456789012']
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. If not specified then the value of the AWS_REGION or EC2_REGION environment variable, if any, is used. See U(http://docs.aws.amazon.com/general/latest/gr/rande.html#ec2_region) type: str ec2_url: aliases: - aws_endpoint_url - endpoint_url description: - 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. type: str profile: aliases: - aws_profile description: - Using I(profile) will override I(aws_access_key), I(aws_secret_key) and I(security_token) and support for passing them at the same time as I(profile) has been deprecated. - I(aws_access_key), I(aws_secret_key) and I(security_token) will be made mutually exclusive with I(profile) after 2022-06-01. 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 aws_config: description: - A dictionary to modify the botocore configuration. - Parameters can be found at U(https://botocore.amazonaws.com/v1/documentation/api/latest/reference/config.html#botocore.config.Config). - Only the 'user_agent' key is used for boto modules. See U(http://boto.cloudhackers.com/en/latest/boto_config_tut.html#boto) for more boto configuration. type: dict purge_tags: default: 'no' description: Whether to remove existing tags that aren't passed in the C(tags) parameter type: bool 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 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 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. - Not used by boto 2 based modules. - 'Note: The CA Bundle is read ''module'' side and may need to be explicitly copied from the controller if not run locally.' type: path aws_access_key: aliases: - ec2_access_key - access_key description: - C(AWS access key). If not set then the value of the C(AWS_ACCESS_KEY_ID), C(AWS_ACCESS_KEY) or C(EC2_ACCESS_KEY) environment variable is used. - If I(profile) is set this parameter is ignored. - Passing the I(aws_access_key) and I(profile) options at the same time has been deprecated and the options will be made mutually exclusive after 2022-06-01. type: str aws_secret_key: aliases: - ec2_secret_key - secret_key description: - C(AWS secret key). If not set then the value of the C(AWS_SECRET_ACCESS_KEY), C(AWS_SECRET_KEY), or C(EC2_SECRET_KEY) environment variable is used. - If I(profile) is set this parameter is ignored. - Passing the I(aws_secret_key) and I(profile) options at the same time has been deprecated and the options will be made mutually exclusive after 2022-06-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 GiB), 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 security_token: aliases: - aws_security_token - access_token description: - C(AWS STS security token). If not set then the value of the C(AWS_SECURITY_TOKEN) or C(EC2_SECURITY_TOKEN) environment variable is used. - If I(profile) is set this parameter is ignored. - Passing the I(security_token) and I(profile) options at the same time has been deprecated and the options will be made mutually exclusive after 2022-06-01. type: str validate_certs: default: true description: - When set to "no", SSL certificates will not be validated for communication with the AWS APIs. 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. type: bool 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: 'no' description: - Use a botocore.endpoint logger to parse the unique (rather than total) "resource:action" API calls made during a task, outputing the set to the resource_actions key in the task results. Use the aws_resource_action callback to output to total list made during a playbook. The ANSIBLE_DEBUG_BOTOCORE_LOGS environment variable may also be used. type: bool
architecture: description: architecture of image returned: when AMI is created or already exists sample: x86_64 type: str 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: str description: description: description of image returned: when AMI is created or already exists sample: nat-server type: str hypervisor: description: type of hypervisor returned: when AMI is created or already exists sample: xen type: str image_id: description: id of the image returned: when AMI is created or already exists sample: ami-1234abcd type: str 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: str name: description: ami name of image returned: when AMI is created or already exists sample: nat-server type: str ownerId: description: owner of image returned: when AMI is created or already exists sample: '435210894375' type: str platform: description: platform of image returned: when AMI is created or already exists sample: null type: str root_device_name: description: root device name of image returned: when AMI is created or already exists sample: /dev/sda1 type: str root_device_type: description: root device type of image returned: when AMI is created or already exists sample: ebs type: str 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: str 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: str