Manipulating EC2 instance storage

1,954 views
Skip to first unread message

Dan Vaida

unread,
Jun 17, 2014, 6:44:54 AM6/17/14
to ansible...@googlegroups.com
Hello everyone!

Here goes my first post in the wonderful Ansible project :)

Here's the problem that I am facing: I am trying to launch an EC2 instance (c3.2xlarge) and, in the process, I want to resize the root partition from 8GB to something bigger. Also while in the process of launching the instance, I'd like to add those two extra disks (2x80GB SSD) that come with this instance.

I do not know if this is even achievable via Ansible.

So far, I looked at these two modules:
- http://docs.ansible.com/ec2_module.html
- http://docs.ansible.com/ec2_vol_module.html

I played with them in different ways, with no avail. Here is what I have now to successfully launch the instance. Playbook: provision.yml
---
# http://docs.ansible.com/ec2_module.html
- name: spin up the all in one instance
  hosts
: localhost
  connection
: local
  gather_facts
: False
  tasks
:

 
- name: create security group
    local_action
:
     
module: ec2_group
      name
: "{{ security_group }}"
      description
: security group for the all in one server
      region
: "{{ region }}"
      vpc_id
: "{{ vpc_id }}"
      rules
:
       
- proto: all
          from_port
: 0
          to_port
: 65535
          cidr_ip
: 87.193.177.242/32
      rules_egress
:
       
- proto: all
          from_port
: 0
          to_port
: 65535
          cidr_ip
: 0.0.0.0/0
   
register: ec2_group
    tags
: provisioning

 
- name: launch instance
    local_action
:
     
module: ec2
      aws_access_key
: "{{ ec2_access_key }}"
      aws_secret_key
: "{{ ec2_secret_key }}"
      count
: 1
      region
: "{{ region }}"
      zone
: "{{ zone }}"
      instance_type
: "{{ instance_type }}"
      image
: "{{ ami }}"
      ebs_optimized
: yes
      state
: present
     
group: "{{ security_group }}"
      vpc_subnet_id
: "{{ subnet }}"
      key_name
: "{{ keypair }}"
      monitoring
: yes
      assign_public_ip
: yes
      wait
: yes
      wait_timeout
: 300
      volumes
:
     
- device_name: /dev/xvda
        volume_size
: 20
   
register: ec2
 
# - name: adding remaining disks #(c3.2xlarge has 2x80GB SSD)
 
#   local_action: ec2_vol instance={{ item.id }} volume_size=80 count=2
 
#   with_items: ec2.instances
 
#   register: ec2_vol

And for what it's worth, here are my variables host_vars/localhost:
#AWS wheezy AMI IDs => https://wiki.debian.org/Cloud/AmazonEC2Image/Wheezy
#(EU-West-1, PVM, EBS-backed, x86_64)region: eu-west-1
zone
: eu-west-1a
instance_type
: c3.2xlarge
ami
: ami-630fcb14

#network & security
security_group
: allinone
subnet
: subnet-ddca27aa
vpc_id
: vpc-9037d9f5
keypair
: ansible-ec2

You can see how I tried and shamefully failed to add those two SSDs (count parameter is not even supported by module ec2_vol) :)
Curiously enough, if I use the volumes parameter of the module ec2 as above, I get two EBS volumes showing up in the AWS console: /dev/sda and of course /dev/xvda (this one being the root device). I cannot even see /dev/sda in the EC2 instance.
FYI, this AMI launches with a 8GB root partition by default. Would be great if I could make that bigger with an Ansible module/parameter. I am very much aware on how to do this "outside" of Ansible, but it's not desired.
Second issue would be attaching those two disks that come with this instance type...

Any help/hint would be greatly appreciated.

See attached screenshot to better understand what I'm trying to achieve with Ansible.

Thank you Michael for this great tool!!

Dan Vaida

unread,
Jun 17, 2014, 4:09:01 PM6/17/14
to ansible...@googlegroups.com
Hello again,

I managed to resize the root device by adjusting the volumes parameter like so:
volumes:
      - device_name: /dev/sda
        volume_size: 20
        device_type: gp2

Hint was found here: New SSD-Backed Elastic Block Storage

Now the only question that remains is: how to add those two SSD drives as well?

Cheers!

Mike Buzzetti

unread,
Aug 21, 2014, 9:01:49 AM8/21/14
to ansible...@googlegroups.com
I just came across this. 

I did something like this for a c3.xlarge. Setting the ephemeral number is the trick (The ssds are considered ephemeral when part of the instance store)


volumes:
  - device_name: /dev/xvdb
    volume_size: 40
    device_type: gp2
    ephemeral: ephemeral0
  - device_name: /dev/xvdc
    volume_size: 40
    device_type: gp2
    ephemeral: ephemeral1

Dan Vaida

unread,
Aug 22, 2014, 3:49:57 AM8/22/14
to ansible...@googlegroups.com
Thanks for sharing this ! Much appreciated :)

The ephemeral disks are indeed SSD's for the instance store.
Message has been deleted

BostonMoto

unread,
Dec 12, 2016, 12:19:35 PM12/12/16
to Ansible Project

I discovered volume_size is also optional when using ephemeral option here, it will default to the maximum size of the instance type spec.
Reply all
Reply to author
Forward
0 new messages