An update to CloudSigma’s Ansible module

Recently, we announced an Ansible module for CloudSigma (or rather, a Dynamic Inventory backend).

I’ve personally started to use Ansible more and more for performing simple tasks. It did however become somewhat cumbersome to use when you have a larger pool of servers.

While still not available in the web app, we have supported Tags for grouping resources for some time. This is a very powerful feature and pairs very well with automation tools; instead of having to explicitly state what servers you want to execute a task on using a long list, or complex regex, you can simply tag them. Since any resource can be tagged with multiple tags, you can create various groupings of your servers (such ‘appservers’, ‘workers’ etc).

Tagging servers

Since this functionality is currently not exposed in the web app, we will have to do it directly in the API. Using our Python library, this is however very simple.

In order to keep things simple, the example below assume that you have the server UUIDs of the servers that you want to tag. You can of course easily build this list yourself by fetching this list of UUIDs matching some criterion.

[python light=”true”] import cloudsigma
tags = cloudsigma.resource.Tags()
my_appservers = [‘uuid0’, ‘uuid1’, ‘uuid2’, ‘uuid3’] tags.create({‘name’: ‘appservers’, ‘resources’: my_appservers})

Ansible and tags

Once you have tagged your servers, you now use this in Ansible (assuming you’ve fetched the latest version of our dynamic inventory backend).

First however, you need to refresh the database by running:
[bash light=”true”] $ /path/to/ –refreshdb

With this done, you should be able to use Ansible with your tagged servers as follows
[bash light=”true”] $ ansible appservers -m ping

You can also use this in your Playbooks, which allows you to simplify your life a lot.

Happy hacking!

Share this Post


About Viktor Petersson

Former VP of Business Development at CloudSigma. Currently CEO at WireLoad and busy making a dent in the Digital Signage industry with Screenly. Viktor is a proud geek and loves playing with the latest technologies.