Ansible is ideal for both configuration management, as well as running automated processes on multiple machines. One could easily cook-up their own scripts for such, but ansible will save you the time from trying to rewrite the book on SSH cluster automation.

Install the EPEL Repository

There is an ansible package available via the EPEL repository. If you haven't already installed the 'epel-release' package, then you should do so now.

yum install epel-release -y

Install Ansible via EPEL Repo

yum install ansible -y

Configure /etc/ansible/hosts

As 'root' user

Most people would suggest using your local user and executing the command via sudo. Well, you may not be 'most people', so if you prefer commandeering as root, then I won't judge you.

vim /etc/ansible/hosts

As your local user via sudo

For those that are bound by the collective 'best practices' borg/hive-mind (or by the dark side of the force), to use sudo, this is for you...

sudoedit /etc/ansible/hosts

Editing /etc/ansible/hosts

Once you're editing the hosts file, you will want to group the servers accordingly. Some may choose the type of application server to use as a single group (i.e. webservers, dbservers, memservers, etc.). Others may choose the server location as a single group (i.e. usa-servers, russia-servers, china-servers), and others may have a combination of both (i.e. usa-db-servers, usa-web-servers, china-web-servers, china-proxy-servers, etc.).

This allows you to execute commands and 'playbooks' on the machines that you have using individual groups, or globally (all).

/etc/ansible/hosts

In this example, I'll use a mixture of hostname AND IP address references, as both are supported.

[mysqld]
db1.mydomain.com
db2.myotherdomain.com
db3.someotherdomain.com
db4.somechineseproxy.com

[httpd]
10.10.100.1
10.10.100.2
10.10.100.3
someremoteserver.com
aws.ipaywaytoomuchforhosting.com

[memcached]
10.10.200.1
10.10.200.2
10.10.200.3

You should now have a working ansible hosts configuration file, with (3) groups of server clusters.

  • httpd - a group of web application servers
  • mysqld - a group of mysql application servers
  • memcached - a group of memcache application servers

Good job, Einstein! You're a rock star admin now.

Execute Commands using the 'shell' module.

Ansible has various modules that can be used to issue commands and execute 'playbooks'. While this article won't get into playbooks or the huge list of modules available, I will cover those at a later time, in separate articles.

Check the uptime of your web servers

ansible httpd -u moo -m shell -a "uptime"

Check the uptime of your database servers

ansible mysqld -u moo -m shell -a "uptime"

Check the stats of your memcached servers

ansible memcached -u moo -m shell -a "memcached-tool localhost stats"

So there you have it. Quick and easily up & running with Ansible. This creates a whole new world for command and control of your machines. I'll let your imagination be your guide, and suggest digging into the ansible documentation to explore your new world in depth.

View my source code on github