steampunk.aws.ec2_volume (0.9.0) — module

Manage EC2 EBS volumes

Authors: Manca Bizjak (@mancabizjak), Aljaz Kosir (@aljazkosir), Saso Stanovnik (@sstanovnik), Miha Dolinar (@mdolinar), Tadej Borovsak (@tadeboro)

preview | supported by XLAB Steampunk

Install collection

Install with ansible-galaxy collection install steampunk.aws:==0.9.0


Add to requirements.yml

  collections:
    - name: steampunk.aws
      version: 0.9.0

Description

Create, update, delete, attach and detach EC2 Elastic Block Store volumes.

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Create an EC2 EBS volume
  ec2_volume:
    name: first-volume
    state: detached
    size_gib: 5
    availability_zone: eun1-az1
  register: my_volume
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Update EC2 EBS volume size
  ec2_volume:
    id: "{{ my_volume.object.id }}"
    state: detached
    size_gib: 15
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Delete EC2 EBS volume
  ec2_volume:
    ids: "{{ my_volume.object.id }}"
    state: absent
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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

Inputs

    
id:
    description:
    - 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 I(name) and I(availability_zone) or I(attachment.instance)
      and I(attachment.device) is used to identify an existing volume.
    type: str

auth:
    description:
    - Parameters for authenticating with the AWS service. Each of them may be defined
      via environment variables.
    suboptions:
      access_key:
        description:
        - The AWS access key ID. If not set, the value of the AWS_ACCESS_KEY environment
          variable will be checked.
        - Mutually exclusive with I(profile).
        required: false
        type: str
      profile:
        description:
        - The name of the AWS profile configured with C(aws configure).
        - Can be used instead of explicitly specifying your access credentials and region.
        - Use C(default) to use the default profile.
        - Mutually exclusive with I(access_key) and I(secret_key).
        required: false
        type: str
      region:
        description:
        - The name of the AWS region.
        - If not set, the value of the AWS_REGION environment variable will be checked.
        - If you set a I(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:
        description:
        - The AWS secret access key. If not set, the value of the AWS_SECRET_KEY environment
          variable will be checked.
        - Mutually exclusive with I(profile).
        required: false
        type: str
      url:
        description:
        - 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_<SERVICE>_URL environment variable
          will be used.
        - The services currently supported are EC2 and S3.
        required: false
        type: str
    type: dict

name:
    description:
    - The name tag of the EBS volume.
    - Required for the creation of the EBS volume.
    type: str

tags:
    description:
    - Metadata for the AWS resource as key/value pairs.
    - Keys and values are case-sensitive.
    type: dict

type:
    choices:
    - gp2
    - st1
    - standard
    description:
    - Type of the EBS volume to create.
    - C(gp2) stands for General Purpose SSD, C(st1) for Throughput Optimized HDD, C(standard)
      for standard Magnetic volumes.
    - Note that the value of this parameter affects the allowed range for the I(size_gib)
      parameter.
    - Refer to U(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 C(gp2)
      will be used.
    type: str

state:
    choices:
    - attached
    - detached
    - absent
    default: attached
    description:
    - The desired state of the volume.
    type: str

size_gib:
    description:
    - The size of the volume to create, in GiBs.
    - The minimum and maximum allowed size depends on the I(type).
    - If C(type=gp2), the allowed range is 1 to 16384 GiB.
    - If C(type=st1), the allowed range is 500 to 16384 GiB.
    - If C(type=standard), the allowed range is 1 to 1024 GiB.
    type: int

attachment:
    description:
    - The configuration for an attachment of the volume to an EC2 instance.
    - Required when creating a new volume if I(state) is C(attached).
    suboptions:
      device:
        description:
        - Make this volume available to the instance as a block device with this name.
        - Refer to U(https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/device_naming.html)
          and U(https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/device_naming.html)
          for more information on available and recommended device names.
        required: true
        type: str
      instance:
        description:
        - The ID of the EC2 instance to attach the volume to.
        required: true
        type: str
      keep_on_termination:
        default: true
        description:
        - Whether the volume should be present after the instance it is attached to is
          terminated.
        type: bool
    type: dict

clear_tags:
    default: false
    description:
    - Whether to clear any existing tags on the resource that are not explicitly stated
      in I(tags).
    - By default, existing tags are kept on the resource.
    - When this parameter is set to C(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 I(name) parameter.
    type: bool

availability_zone:
    description:
    - ID of the availability zone in which to create the volume.
    - Required when creating a volume if I(state) is C(detached).
    - Mutually exclusive with I(attachment), as the module will automatically set the
      value of this parameter to the availability zone of I(attachment.instance).
    type: str

Outputs

object:
  contains:
    attachment:
      contains:
        device:
          description: Name of the block device under which this volume is available
            to the instance.
          returned: always
          type: str
        instance:
          description: The ID of the instance the volume is attached to.
          returned: always
          type: str
        keep_on_termination:
          description: Whether the volume is preserved when terminating the instance.
          returned: always
          type: bool
      description: The attachment of this volume to an instance, if any.
      returned: when I(state=attached)
      type: dict
    availability_zone:
      description: The ID of the availability zone in which the volume exists.
      returned: always
      type: str
    id:
      description: The ID of the volume.
      returned: always
      type: str
    size_gib:
      description: Size of the volume in GiB.
      returned: always
      type: int
    state:
      description: State of the EC2 volume as reported by AWS.
      returned: always
      type: str
    tags:
      description: The tags assigned to this volume.
      returned: always
      type: dict
    type:
      description: The type of the volume.
      returned: always
      type: str
  description:
  - A representation of the EC2 EBS volume.
  returned: success and C(state=[attached|detached])
  sample:
    object:
      attachment:
        device: /dev/sdf
        instance: i-18fg46a2dsd
        keep_on_termination: true
      availability_zone: eun1-az1
      id: vol-07bf55269d200d90e
      size_gib: 5
      state: available
      tags:
        Name: myfirstvolume
      type: standard
  type: dict

See also