Ansible

A

Ansible can be described as an open-source configuration management app, allowing a user to provision software and provides tools to deploy apps on a wide variety of physical and virtual servers, regardless of the OS, both on Unix, Linux, and Microsoft Windows. It also features its’ own language which helps developers describe the system configuration.

We can do the following using Ansible as a system administrator:
1. Install applications on servers;
2. Install security patches and patches;
3. Manage and update application configurations;
4. Manage server-side services;
5. Manage users on servers;
6. Manage databases;
7. Manage network equipment.

And on the user side:
1. Reduces the repeatability of operations;
2. Runs simultaneously on several machines;
3. Simplifies config creation by using templates and variables;
4. Troubleshoots problems caused by configuration errors.

If we use Ansible as a developer, it allows replicating the perfectly functional production infrastructure on the local station in a brief time.

Benefits:
1. There is no need to install additional software on worker machines;
2. Easy to use at a tiny scale with a small number of managed devices.
3. It does not require another service running on the control machine.

Limitations:
1. It is necessary to add the public key to connect to the slave machines;
2. In a large number of managed machines, runtimes may increase, the master machine must connect to each slave to run the commands.

Ansible is a very easy to use application that allows multiple server administration such as package installation, configuration, service administration, but also application deployments, container creation, and everything is done through the included modules.

The commands are very intuitive and can be grouped to run them in yaml playbooks. Ansible can be installed from the used distribution repository or in Python mode.

Installation in CentOS from repo EPEL:

yum install epel-release
yum install ansible
Installation in Ubuntu / Debian
apt-add-repository -pppa: ansible / ansible
apt update
apt install -y ansible

Install in Python Mode:

pip install ansible
Ansible – use playbooks

In the official documentation from Ansible, playbooks, playbooks, are defined as configure, deploy and orchestration languages.

An example (apache.yml):

   hosts: webservers
  Aquarius:
    http_port: 80
    max_clients: 200
  remote_user: ubuntu
  became: yes
  tasks:
    – name: ensure apache is 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

where the terms are explained as:

1.hosts – the machine or group of machines where we execute the commands,
2. vars – variables/parameters used to run commands or to generate configuration files from templates,
3. remote user – the SSH connection used; can be defined in ansible.cfg or in inventory at machine level;
4. name – if we want to execute commands as root;
5. tasks – the list of commands that are being executed.

The list of tasks (orders) are executed in a sequence, one by one on all the machines defined in the hosts parameter, and in case a command fails on a machine from it, the rest of the orders in the list are not executed.

Tasks are defined by:

    name – suggestive description of the command being executed,
    the module used with the specific parameters according to the documentation

Execution parameters can be defined as key = value:

About the author

Ilias spiros
By Ilias spiros

Recent Posts

Archives

Categories