Ansible

Automation tool for configuration management and application deployment

Introduction

Ansible is an open-source software provisioning, configuration management, and application-deployment tool. A feature of Ansible is that it uses an agentless architecture. This means the is no need for a daemon, also meaning no resource is taken when Ansible is not running. Ansible orchestrates a node by installing and running modules on the node temporarily via SSH. [1]

Alternative tool Chef | Puppet | CFEngine

What is the use case?

Let's say you have more than one computer you want to access or manage. Do you want to run the same commands on every system or want to configure all systems the same way? Instead of using SSH to get to each server by hand, you only want to type the code once and everything should be executed on all system.

Here you can use Ansible. You want to echo "Hi" on all systems, then type this on your control node:

ansible all -m shell -a "echo Hi"

all means we want to execute this command on all managed nodes. The managed nodes must be configured first in /etc/ansible/hosts

-m shell means we are using the shell module. There are several modules to choose from.

-a referees to the module arguments, here we want to use the shell to command: "echo Hi"

What about more complex commands?

Instead of typing all commands one after another, you can use an Ansible Playbook. Here you can write down a task list, of what would be executed. Here is an example of a playbook.

ansible-playbook.yml
---
- hosts: webservers
  vars:
    http_port: 80
    max_clients: 200
  remote_user: root

  tasks:
  - name: ensure apache is at the latest version
    yum:
      name: httpd
      state: latest
      
  - name: write the apache config file
    template:
      src: /srv/httpd.j2
      dest: /etc/httpd.conf
    notify:
    - restart apache
    
  - name: ensure apache is running
    service:
      name: httpd
      state: started
      
  handlers:
    - name: restart apache
      service:
        name: httpd
        state: restarted

Resources

Ansible Documentation |

List of sources

[1] wikipedia.org - https://en.wikipedia.org/wiki/Ansible_(software)

Last updated