ec2_vol - create and attach a volume, return volume id and device map

Author:Lester Wade

Synopsis

New in version 1.1.

creates an EBS volume and optionally attaches it to an instance. If both an instance ID and a device name is given and the instance has a device at the device name, then no volume is created and no attachment is made. This module has a dependency on python-boto.

Options

parameter required default choices comments
aws_access_key no
    AWS access key. If not set then the value of the AWS_ACCESS_KEY environment variable is used.
    aws_secret_key no
      AWS secret key. If not set then the value of the AWS_SECRET_KEY environment variable is used.
      device_name no
        device id to override device mapping. Assumes /dev/sdf for Linux/UNIX and /dev/xvdf for Windows.
        ec2_url no
          Url to use to connect to EC2 or your Eucalyptus cloud (by default the module will use EC2 endpoints). Must be specified if region is not used. If not set then the value of the EC2_URL environment variable, if any, is used
          id no
            volume id if you wish to attach an existing volume (requires instance) or remove an existing volume (added in Ansible 1.6)
            instance no
              instance ID if you wish to attach the volume.
              iops no 100
                the provisioned IOPs you want to associate with this volume (integer). (added in Ansible 1.3)
                name no
                  volume Name tag if you wish to attach an existing volume (requires instance) (added in Ansible 1.6)
                  profile no
                    uses a boto profile. Only works with boto >= 2.24.0 (added in Ansible 1.6)
                    region no
                      The AWS region to use. If not specified then the value of the EC2_REGION environment variable, if any, is used.
                      security_token no
                        security token to authenticate against AWS (added in Ansible 1.6)
                        snapshot no
                          snapshot ID on which to base the volume (added in Ansible 1.5)
                          state no present
                          • absent
                          • present
                          whether to ensure the volume is present or absent (added in Ansible 1.6)
                          validate_certs no yes
                          • yes
                          • no
                          When set to "no", SSL certificates will not be validated for boto versions >= 2.6.0. (added in Ansible 1.5)
                          volume_size no
                            size of volume (in GB) to create.
                            zone no
                              zone in which to create the volume, if unset uses the zone the instance is in (if set)

                              Note

                              Requires boto

                              Examples


                              # Simple attachment action
                              - local_action:
                                  module: ec2_vol
                                  instance: XXXXXX
                                  volume_size: 5
                                  device_name: sdd
                              
                              # Example using custom iops params
                              - local_action:
                                  module: ec2_vol
                                  instance: XXXXXX
                                  volume_size: 5
                                  iops: 200
                                  device_name: sdd
                              
                              # Example using snapshot id
                              - local_action:
                                  module: ec2_vol
                                  instance: XXXXXX
                                  snapshot: "{{ snapshot }}"
                              
                              # Playbook example combined with instance launch
                              - local_action:
                                  module: ec2
                                  keypair: "{{ keypair }}"
                                  image: "{{ image }}"
                                  wait: yes
                                  count: 3
                                  register: ec2
                              - local_action:
                                  module: ec2_vol
                                  instance: "{{ item.id }} "
                                  volume_size: 5
                                  with_items: ec2.instances
                                  register: ec2_vol
                              
                              # Example: Launch an instance and then add a volue if not already present
                              #   * Nothing will happen if the volume is already attached.
                              #   * Volume must exist in the same zone.
                              
                              - local_action:
                                  module: ec2
                                  keypair: "{{ keypair }}"
                                  image: "{{ image }}"
                                  zone: YYYYYY
                                  id: my_instance
                                  wait: yes
                                  count: 1
                                  register: ec2
                              
                              - local_action:
                                  module: ec2_vol
                                  instance: "{{ item.id }}"
                                  name: my_existing_volume_Name_tag
                                  device_name: /dev/xvdf
                                  with_items: ec2.instances
                                  register: ec2_vol
                              
                              # Remove a volume
                              - local_action:
                                  module: ec2_vol
                                  id: vol-XXXXXXXX
                                  state: absent
                              

                              Note

                              The following environment variables can be used AWS_ACCESS_KEY or EC2_ACCESS_KEY or AWS_ACCESS_KEY_ID, AWS_SECRET_KEY or EC2_SECRET_KEY or AWS_SECRET_ACCESS_KEY, AWS_REGION or EC2_REGION, AWS_SECURITY_TOKEN

                              Note

                              Ansible uses the boto configuration file (typically ~/.boto) if no credentials are provided. See http://boto.readthedocs.org/en/latest/boto_config_tut.html

                              Note

                              AWS_REGION or EC2_REGION can be typically be used to specify the AWS region, when required, but this can also be configured in the boto config file