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) ;)
The resulting doc bits are here: http://ansible.cc/docs/modules.html#ec2-vol whilst the code lives here: https://github.com/ansible/ansible/blob/devel/library/ec2_vol
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 ;)
– Detect existing device mappings via instance.block_device_mapping and then adjust the attachment device appropriately.
I’ll probably attempt this in a couple of months. This would work fine under EC2 but tagging and *full* block device mapping support won’t be in Eucalyptus until version 3.3 (due end of Q2 this year). See here for more details: https://eucalyptus.atlassian.net/browse/EUCA-4786 and https://eucalyptus.atlassian.net/browse/EUCA-2117.
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.