How to use Ansible

In this article we will see what is and how to use Ansible, so we will start with a brief introduction.

Introduction to Ansible

Ansible is an open source configuration automation tool for system and application management. It is designed to simplify system configuration, application deployment and infrastructure management. Ansible runs on a controller machine and communicates with remote systems via SSH. This means that you do not need to install any software on the remote systems for Ansible to manage them.

Ansible is a very useful configuration automation tool for system administrators. It can help save time by automating repetitive and tedious tasks. Ansible can also help ensure that systems are configured consistently. This is especially useful when managing many systems.

Installation of Ansible

Installing Ansible on CentOS

Ansible can be installed on CentOS using the yum package manager. First, update the list of available packages:

$ sudo yum update

Next, install the ansible package:

$ sudo yum install ansible

Once the installation is complete, check the Ansible version:

$ ansible --version

Installing Ansible on Ubuntu

As in CentOs, Ansible can be installed on Ubuntu using the apt package manager. First, update the list of available packages:

$ sudo apt update

Next, install the ansible package:

$ sudo apt install ansible

Once the installation is complete, check the Ansible version:

$ ansible --version

Installing Ansible on Arch Linux

As with the previous two distributions, Ansible can be installed on Arch Linux using the native package manager, in this case pacman.

First, update the list of available packages:

$ sudo pacman -Syu

Next, install the ansible package:

$ sudo pacman -S ansible

Once the installation is complete, check the Ansible version:

$ ansible --version

Ansible configuration

Once Ansible is installed, it must be configured to communicate with remote systems. This is done by editing the Ansible configuration file, which is located in /etc/ansible/ansible.cfg.

In this file, there are several options that can be configured. For example, you can specify the inventory directory, the role set directory, the template directory, and so on.

You can also specify the user that will be used to connect to the remote systems. This is done by editing the remote_user option in the configuration file.

Using Ansible

Once Ansible is configured, it can be used to automate tasks on remote systems. This is done by writing scripts in YAML, which are known as playbooks.

A playbook is a set of tasks to be performed on a remote system. These tasks may include installing packages, configuring services, creating users, etc.

Below is an example of an Ansible playbook for installing Apache on a remote system:

---
- hosts: all
become: true
tasks:
- name: Install Apache
yum:
name: httpd
state: present

In this example, the playbook will run on all remote systems (hosts: all). The user to be used to connect to the remote systems will be the one specified in the Ansible configuration file (become: true).

The task to be executed on the remote systems is the installation of Apache (name: Install Apache). This task will be performed using the yum package manager (yum:). The package to be installed is httpd (name: httpd) and the desired state is present (state: present).

Conclusion

Ansible is a very useful open source configuration automation tool for system administrators. It can help save time by automating repetitive and tedious tasks. Ansible can be installed on CentOS, Ubuntu, Arch and other distributions using the appropriate package manager. Once installed, it must be configured to communicate with remote systems. Ansible is used to automate tasks on rcemote systems by writing scripts in YAML, which are known as playbooks.

Leave a Reply