.. meta:: :description: Create, update, delete, attach and detach EC2 Elastic Block Store volumes. .. _ec2_volume_module: ec2_volume -- Manage EC2 EBS volumes ==================================== Create, update, delete, attach and detach EC2 Elastic Block Store volumes. Examples -------- .. code-block:: yaml+jinja - name: Create an EC2 EBS volume ec2_volume: name: first-volume state: detached size_gib: 5 availability_zone: eun1-az1 register: my_volume - name: Update EC2 EBS volume size ec2_volume: id: "{{ my_volume.object.id }}" state: detached size_gib: 15 - name: Attach the first-volume to the EC2 instance ec2_volume: name: first-volume attachment: instance: i-18fg46a2dsd device: /dev/sdg keep_on_termination: no - name: Delete EC2 EBS volume ec2_volume: ids: "{{ my_volume.object.id }}" state: absent - name: Create another EC2 EBS volume and attach it to the instance ec2_volume: name: second-volume type: standard size_gib: 20 attachment: instance: i-18fg46a2dsd device: /dev/sdf keep_on_termination: yes See Also -------- .. seealso:: - :ref:`ec2_volume_info_module` Parameters ---------- attachment (optional) The configuration for an attachment of the volume to an EC2 instance. Required when creating a new volume if *state* is ``attached``. | **type**: dict device (required) Make this volume available to the instance as a block device with this name. Refer to https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/device_naming.html and https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/device_naming.html for more information on available and recommended device names. | **type**: str instance (required) The ID of the EC2 instance to attach the volume to. | **type**: str keep_on_termination (optional) Whether the volume should be present after the instance it is attached to is terminated. | **type**: bool | **default**: True auth (optional) Parameters for authenticating with the AWS service. Each of them may be defined via environment variables. | **type**: dict access_key (optional) The AWS access key ID. If not set, the value of the AWS_ACCESS_KEY environment variable will be checked. Mutually exclusive with *profile*. | **type**: str profile (optional) The name of the AWS profile configured with ``aws configure``. Can be used instead of explicitly specifying your access credentials and region. Use ``default`` to use the default profile. Mutually exclusive with *access_key* and *secret_key*. | **type**: str region (optional) The name of the AWS region. If not set, the value of the AWS_REGION environment variable will be checked. If you set a *profile* that specifies a default region, that region is used and you can omit this parameter. Use this parameter to override the profile's default region. | **type**: str secret_key (optional) The AWS secret access key. If not set, the value of the AWS_SECRET_KEY environment variable will be checked. Mutually exclusive with *profile*. | **type**: str url (optional) The URL to the AWS service related to the resource. By default, this is automatically determined through the region parameter. If not set explicitly, the value of the AWS__URL environment variable will be used. The services currently supported are EC2 and S3. | **type**: str availability_zone (optional) ID of the availability zone in which to create the volume. Required when creating a volume if *state* is ``detached``. Mutually exclusive with *attachment*, as the module will automatically set the value of this parameter to the availability zone of *attachment.instance*. | **type**: str clear_tags (optional) Whether to clear any existing tags on the resource that are not explicitly stated in *tags*. By default, existing tags are kept on the resource. When this parameter is set to ``true``, any pre-existing tags on the resource (including the name tag) are removed. To clear all tags except the name tag, make sure to provide the *name* parameter. | **type**: bool id (optional) ID of the EBS volume to perform the task on. If specified, this parameter is used to identify the volume. If omitted, a combination of *name* and *availability_zone* or *attachment.instance* and *attachment.device* is used to identify an existing volume. | **type**: str name (optional) The name tag of the EBS volume. Required for the creation of the EBS volume. | **type**: str size_gib (optional) The size of the volume to create, in GiBs. The minimum and maximum allowed size depends on the *type*. If ``type=gp2``, the allowed range is 1 to 16384 GiB. If ``type=st1``, the allowed range is 500 to 16384 GiB. If ``type=standard``, the allowed range is 1 to 1024 GiB. | **type**: int state (optional) The desired state of the volume. | **type**: str | **default**: attached | **choices**: attached, detached, absent tags (optional) Metadata for the AWS resource as key/value pairs. Keys and values are case-sensitive. | **type**: dict type (optional) Type of the EBS volume to create. ``gp2`` stands for General Purpose SSD, ``st1`` for Throughput Optimized HDD, ``standard`` for standard Magnetic volumes. Note that the value of this parameter affects the allowed range for the *size_gib* parameter. Refer to https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-volume-types.html for more information on EBS volume types. If you omit this parameter when creating an EC2 volume, the default type ``gp2`` will be used. | **type**: str | **choices**: gp2, st1, standard Return Values ------------- object (success and C(state=[attached|detached])), dict, {'object': {'id': 'vol-07bf55269d200d90e', 'type': 'standard', 'size_gib': 5, 'availability_zone': 'eun1-az1', 'tags': {'Name': 'myfirstvolume'}, 'state': 'available', 'attachment': {'instance': 'i-18fg46a2dsd', 'device': '/dev/sdf', 'keep_on_termination': True}}} A representation of the EC2 EBS volume. id (always), str, The ID of the volume. type (always), str, The type of the volume. size_gib (always), int, Size of the volume in GiB. availability_zone (always), str, The ID of the availability zone in which the volume exists. tags (always), dict, The tags assigned to this volume. state (always), str, State of the EC2 volume as reported by AWS. attachment (when I(state=attached)), dict, The attachment of this volume to an instance, if any. instance (always), str, The ID of the instance the volume is attached to. device (always), str, Name of the block device under which this volume is available to the instance. keep_on_termination (always), bool, Whether the volume is preserved when terminating the instance.