JoeHack3r

Eat like a bird, and poop like an elephant --Japanese philosopher

First Ansible Contribution - Delete EBS Volume on Instance Termination

After a few months of using Ansible, I became a contributor on March 18, 2014. The term contributor should be used lightly as it was only a documentation change, although a worthwhile one. Recently, the EC2 module was updated to include volumes. This change is noteworthy as it allows users to pass Block Device Mapping when running (creating) instances. A common use of BDM is to attach volumes at instance launch and set them to delete when the instance terminates. This is useful to prevent EBS volume sprawl (one challenge I’ve had with using Ansible).

However, the examples didn’t show how to do this.

So I forked the repository, updated an example, and submitted a pull request. It may take a few days before the documentation is updated, so here is a sneak peak:

Update example to include delete on termination mark:16
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# Single instance with additional IOPS volume from snapshot and volume delete on termination
local_action:
    module: ec2
    key_name: mykey
    group: webserver
    instance_type: m1.large
    image: ami-6e649707
    wait: yes
    wait_timeout: 500
    volumes:
    - device_name: /dev/sdb
      snapshot: snap-abcdef12
      device_type: io1
      iops: 1000
      volume_size: 100
      delete_on_termination: true
    monitoring: yes

I hope you find this useful. If you want more, connect with me via twitter:


Comments