ansible / ansible.builtin / v2.4.3.0-1 / 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> stableinterface | supported by certifiedansible.builtin.ec2_ami (v2.4.3.0-1) — module
pip
Install with pip install ansible==2.4.3.0.post1
Creates or deletes ec2 images.
# Basic AMI Creation - ec2_ami: aws_access_key: xxxxxxxxxxxxxxxxxxxxxxx aws_secret_key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx instance_id: i-xxxxxx wait: yes name: newtest tags: Name: newtest Service: TestService register: image
# Basic AMI Creation, without waiting - ec2_ami: aws_access_key: xxxxxxxxxxxxxxxxxxxxxxx aws_secret_key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx region: xxxxxx instance_id: i-xxxxxx wait: no name: newtest register: image
# AMI Registration from EBS Snapshot - ec2_ami: aws_access_key: xxxxxxxxxxxxxxxxxxxxxxx aws_secret_key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx region: xxxxxx name: newtest state: present architecture: x86_64 virtualization_type: hvm root_device_name: /dev/xvda device_mapping: - device_name: /dev/xvda size: 8 snapshot_id: snap-xxxxxxxx delete_on_termination: true volume_type: gp2 register: image
# AMI Creation, with a custom root-device size and another EBS attached - ec2_ami: aws_access_key: xxxxxxxxxxxxxxxxxxxxxxx aws_secret_key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 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 register: image
# AMI Creation, excluding a volume attached at /dev/sdb - ec2_ami: aws_access_key: xxxxxxxxxxxxxxxxxxxxxxx aws_secret_key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 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 register: image
# Deregister/Delete AMI (keep associated snapshots) - ec2_ami: aws_access_key: xxxxxxxxxxxxxxxxxxxxxxx aws_secret_key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx region: xxxxxx image_id: "{{ instance.image_id }}" delete_snapshot: False state: absent
# Deregister AMI (delete associated snapshots too) - ec2_ami: aws_access_key: xxxxxxxxxxxxxxxxxxxxxxx aws_secret_key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx region: xxxxxx image_id: "{{ instance.image_id }}" delete_snapshot: True state: absent
# Update AMI Launch Permissions, making it public - ec2_ami: aws_access_key: xxxxxxxxxxxxxxxxxxxxxxx aws_secret_key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx region: xxxxxx image_id: "{{ instance.image_id }}" state: present launch_permissions: group_names: ['all']
# Allow AMI to be launched by another account - ec2_ami: aws_access_key: xxxxxxxxxxxxxxxxxxxxxxx aws_secret_key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx region: xxxxxx image_id: "{{ instance.image_id }}" state: present launch_permissions: user_ids: ['123456789012']
name: default: null description: - The name of the new AMI. required: false tags: default: null description: - A dictionary of tags to add to the new image; '{"key":"value"}' and '{"key":"value","key":"value"}' required: false version_added: '2.0' version_added_collection: ansible.builtin wait: choices: - 'yes' - 'no' default: 'no' description: - Wait for the AMI to be in state 'available' before returning. required: false state: choices: - absent - present default: present description: - Create or deregister/delete AMI. required: false 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 profile: aliases: - aws_profile description: - 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: default: null description: - Image ID to be deregistered. required: false kernel_id: default: null description: - The target kernel id of the image to register required: false version_added: '2.3' version_added_collection: ansible.builtin no_reboot: choices: - 'yes' - 'no' 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. required: false 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). type: dict description: default: null description: - Human-readable string describing the contents and purpose of the AMI. required: false instance_id: default: null description: - Instance ID to create the AMI from. required: false architecture: default: null description: - The target architecture of the image to register required: false version_added: '2.3' version_added_collection: ansible.builtin endpoint_url: aliases: - ec2_url - aws_endpoint_url - s3_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 wait_timeout: default: 300 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. - '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. - The I(aws_access_key) and I(profile) options are mutually exclusive. 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. - The I(aws_secret_key) and I(profile) options are mutually exclusive. type: str device_mapping: default: null description: - List of device hashes/dictionaries with custom configurations (same block-device-mapping parameters) - 'Valid properties include: device_name, volume_type, size (in GB), delete_on_termination (boolean), no_device (boolean), snapshot_id, iops (for io1 volume_type) ' required: false version_added: '2.0' version_added_collection: ansible.builtin security_token: aliases: - aws_session_token - session_token - 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. - The I(security_token) and I(profile) options are mutually exclusive. - Aliases I(aws_session_token) and I(session_token) have been added in version 3.2.0. 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: choices: - 'yes' - 'no' default: 'no' description: - Delete snapshots when deregistering the AMI. required: false root_device_name: default: null description: - The root device name of the image to register required: false version_added: '2.3' version_added_collection: ansible.builtin launch_permissions: default: null 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. required: false version_added: '2.0' version_added_collection: ansible.builtin virtualization_type: default: null description: - The virtualization type of the image to register required: false 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: 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 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