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 cloudsigmatags = cloudsigma.resource.Tags()
my_appservers = [‘uuid0’, ‘uuid1’, ‘uuid2’, ‘uuid3’] tags.create({‘name’: ‘appservers’, ‘resources’: my_appservers})
[/python]
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/ansiblecs.py –refreshdb
[/bash]
With this done, you should be able to use Ansible with your tagged servers as follows
[bash light=”true”]
$ ansible appservers -m ping
[/bash]
You can also use this in your Playbooks, which allows you to simplify your life a lot.
Happy hacking!
Share this Post
- Manage Docker resources with Cgroups - May 12, 2015
- Docker, Cgroups & More from ApacheCon 2015 - April 30, 2015
- How to setup & optimise MongoDB on public cloud servers - March 24, 2015
- Presentation deck from CloudExpo Europe - March 17, 2015
- CoreOS is now available on CloudSigma! - March 10, 2015