Lester's Technology Musings …

Menu

Writing my first Ansible module: ec2_vol

As is probably quite evident, I’ve recently been using Ansible to deploy workloads into EC2 and Eucalyptus. One of the ideas behind this is the convenience of being able to leverage the common API to achieve a hybrid deployment scenario. Thanks to various folk (names mentioned in previous posts) we have a solid ec2 boto-based Python module for instance launching. One thing I wanted to do when spinning up instances and configuring a workload was to add some persistent storage for the application. To do this I had to create and attach a volume as a manual step or run a local_action against euca2ools. I figured I could try to write my own module to practice a bit more python (specifically boto). The result is something terribly (perhaps in more ways that one?) simple but I think this is a testament to just how easy it is to write modules for Ansible (p.s it doesn’t need to be Python) ;)

In a future post I’ll write a little bit about how it works, hopefully this can inspire other folks to try writing some additional EC2 modules for Ansible :)

It’s really very rudimentary but it does what it says on the tin. Having spoken to Seth (and others) about this, some improvements for future versions would be:

– Make it idempotent. In practical terms make it possible to run the module without changes to the system. This would be possible via a state parameter (see other modules): present/absent. The code could then check for a volume attached to a particular instance which is tagged with the specified tag. If it doesn’t exist, add it. If it does, pass over it. I’d call this the ec2 volume passover module ;)

As we continue to bring better feature compatibility with AWS, it makes these kind of hybrid things much easier :) We’re also going to need to address some of the other AWS services with Ansible modules I think, like ELB, CloudWatch etc.