Here at Cloudar we’re using Ansible to automate deployments. We quickly realised its potential to orchestrate custom and more complicated automation
Recently we were looking for a way to automate the following actions.
- Creating snapshots
- Starting and stopping instances
- Removing old snapshots
We already had a script and cronjob to take regular snapshots, but we wanted to centralise our automation to improve visibility and logging.
While this is possible using the existing Ansible modules, we needed a way to specify multiple parameters on a per instance basis. Specifically we needed it to be possible to:
- Change the start and stop times from within the AWS Console
- Allow users without access to (or knowledge of) Ansible to prevent the automatic shutdown of a machine
We quickly decided to use tags to specify these parameters. Because there’s a limit of ten tags per instance, and we wanted to store other information (like Environment and Project) too, it wasn’t possible to store each parameter in a separate tag.
We solved this by writing our own Ansible modules. Each module reads the same tag, where we store a JSON dictionary with all the needed variables. This way we keep room for other tags, while allowing everyone with the right to create tags to change things if they need to.