Server automation – Introducing ansible

Ansible is a tool I find myself using more and more. To quote the project website:

Ansible is the simplest way to automate and orchestrate.

Indeed, ansible is the simplest way to automate. Once installed and a hostfile is setup (this is really an ini-like file, with section headers and lists of hostname), you can run any command, via sudo (or not) on the list of hosts defined, in parallel, without having to login manually on all machines.

A small example will show you the power of its command line. I just wanted to stop puppet on all our disco slaves. I thus defined a  /etc/ansible.host file as follow:

[disco]
slave1
slave2
...
slave16

Then I just needed to type:

ansible disco --inventory-file /etc/ansible.hosts --ask-sudo-pass --forks=5 -a "service pupwrapd stop"

And voila, pupwrapd was stopped on all servers, with 5 open connections. I could of course have done it on all 16 servers in parallel.

This is just the tiny top of the ansible iceberg. This is a very dynamic project, always evolving and improving, with the possibility to write scripts to do just about everything. There are a lot of modules including which will make your life a lot easier, and the documentation is quite comprehensive.

In short, if you do not know ansible yet, have a look!

Advertisement