Ansible can be very useful for Swarm cluster administration. See the extensive documentation on Ansible at docs.Ansible.com.
Following is basic setup and configuration.
The simplest way to install Ansible is to use yum on a RHEL/CentOS server. This will typically get you version 2.1 or 2.3 of Ansible, which not the latest version (2.9, at time of writing) but would be usable for most operations.
To get a newer version, first install epel-release and then install Ansible:
[root@caringoadminserver /]# yum install epel-release -y
[root@caringoadminserver /]# yum install ansible
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirror.ox.ac.uk
* epel: fedora.cu.be
* extras: ftp.heanet.ie
* updates: mirror.sov.uk.goscomb.net
--> Running transaction check
---> Package ansible.noarch 0:2.9.3-1.el7 will be updated
---> Package ansible.noarch 0:2.9.6-1.el7 will be an update
--> Finished Dependency Resolution
Package Arch Version Repository Size
ansible noarch 2.9.6-1.el7 epel 17 M
Upgrade 1 Package
Total download size: 17 M
Is this ok [y/d/N]: y
epel/x86_64/prestodelta | 2.2 kB 00:00:00
ansible-2.9.6-1.el7.noarch.rpm | 17 MB 00:00:03
Running transaction check
Running transaction test
Transaction test succeeded
Updating : ansible-2.9.6-1.el7.noarch 1/2
Cleanup : ansible-2.9.3-1.el7.noarch 2/2
Verifying : ansible-2.9.6-1.el7.noarch 1/2
Verifying : ansible-2.9.3-1.el7.noarch 2/2
The minimal dependencies required for Ansible are taken care of during the install procedure above.
Ansible uses parallel ssh sessions to manage the hosts, and this can be configured to use existing ssh keys. The managed hosts should be set up to use password-less auth from the server where Ansible is installed.
For simplicity, we'll use the root user for now, as that is available on all systems.
In production, always configure an Ansible user per system that you plan to pull under orchestration and use that Ansible user when making changes.
Breaking this down, the Ansible command means we are using Ansible in ad-hoc mode.
The "allcaringo" section refers to the hosts in the host inventory we created earlier. If we were to replace "allcaringo" with "elasticsearch", the command would only apply to the 2 elasticsearch hosts we have defined.
The -m flag refers to the module we're using, in this case "ping". Modules are pre-written tool sets that allow you to run commands against multiple hosts.
There are hundreds of modules. Here are a few basic ones that are frequently used:
ping a host
compress a file
run a command on a host
check for a line of text in a file and add it if not present
start stop enable a service
make a http call to a url
install a package on a RHEL/CentOS host
interact with PAM
apply a template of a file e.g. config file
We'll review these and others in more detail separately.