Flexible Instance and Snapshot management with Ansible

03/04/2015
Posted in AWS Blog
03/04/2015 Ben Bridts



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.

The source code is available on GitHub. You can install it by adding the path to your Ansible Library. Complete usage instructions and examples are included in the repository.


  • SHARE
, , , , ,

Comments (4)

  1. Avatar
    klemen

    ever thought about contacting ansible author and merging (something like) this in ansible?

    • Avatar
      Ben Bridts

      Hi Klemen,

      I think that these modules are a bit too specific to our workflow to be a good part of the Ansible Extra Modules, so we didn’t reach out to the Ansible team.

      That being said, it would be very nice to get this shipped with Ansbile.

  2. Avatar
    prasan

    hey, I am getting following error while i am running this code. Any idea? am i missing anything?

    An exception occurred during task execution. The full traceback is:
    Traceback (most recent call last):
    File “/tmp/ansible-tmp-1463012517.56-174809243965973/cat_create_snapshot”, line 2393, in
    main()
    File “/tmp/ansible-tmp-1463012517.56-174809243965973/cat_create_snapshot”, line 86, in main
    if grace_minutes.isdigit():
    AttributeError: ‘int’ object has no attribute ‘isdigit’


    – name: Snap
    hosts: tag_Backup_true
    connection: local
    gather_facts: false
    tasks:
    – name: Create Snapshot
    local_action:
    module: cat_create_snapshot
    tag: CAT
    grace: 10

    • Avatar
      Ben Bridts

      Hey Prasan,

      Are you using Ansible 2.x? This module was written for ansible 1.9.x and the way parameters are passed may have changed. Can you try with using grace: ’10’ (inside quotes) or not changing the grace time?

      Kind regards,
      Ben

Leave a Reply

Your email address will not be published. Required fields are marked *

LET'S WORK
TOGETHER

Need a hand? Or a high five?
Feel free to visit our offices and come say hi
… or just drop us a message

We are ready when you are

Cloudar NV – Operations

Veldkant 7
2550 Kontich (Antwerp)
Belgium

info @ cloudar.be

+32 3 450 67 18

Cloudar NV – HQ

Veldkant 33A
2550 Kontich (Antwerp)
Belgium

VAT BE0564 763 890

    This contact form is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

    contact
    • SHARE