Ansible

IT and Infrastructure automation

Setup

Install the EPEL repository and Ansible (or just Ansible directly)

$ sudo yum install -y epel-release
$ sudo yum install -y ansible

In its simplest form, Ansible works by workstations controlled by a control host. On both, you will need a consistent ansible user:

$ sudo useradd ansible
$ sudo passwd ansible # set a password for the user

Configure a shared key that will allow the user to log in from the control host to the workstation without password prompts:

# On the control host
$ sudo su - ansible
$ ssh-keygen
$ ssh-copy-id <workstation> # provide your ansible password here
$ logout

Configure the ansible user on the workstation host so that the ansible control host user can sudo without a password:

$ sudo visudo
# At the bottom of the file add:
ansible ALL=(ALL) NOPASSWD: ALL

Inventory

The inventory is just a list of hosts available to you in a file called inventory. Inventories will look like this:

[group_name]
node1_local_name
node2_local_name

Playbooks

Ansible playbooks are configuration files that define what you're doing to your workstation nodes in simple YAML or JSON. The following is a good playbook model for installing git on the workstation:

git-setup.yml
  --- # install git on target host
  - hosts: workstation
    become: yes
    tasks:
    - name: install git
      yum:
        name: git
        state: latest

Execute

Execute the playbook with:

$ ansible-playbook -i /home/ansible/inventory /home/ansible/git-setup.yml

Pings

Check health of a node by pinging it (you can redirect or tail output to a log):

$ ansible -i /home/ansible/inventory node2 -m ping > /home/ansible/output

Last updated

Was this helpful?