Ansible is an open-source automation tool for the configuration and management of IT infrastructures. It allows for the easy management of numerous servers using YAML to describe automated tasks. Ansible operates agentlessly, meaning there is no need to install additional software on the nodes it manages.

Ansible is popular for several reasons:

  • Simplicity and ease of use: The playbooks (configuration files) are written in YAML, a simple and human-readable language.
  • Powerful and flexible: Ansible can handle complex tasks and adapt to various environments.
  • Agentless: No need to install software on the managed nodes, simplifying management and security.
  • Idempotent: Playbooks can be run multiple times without causing undesirable or unintended effects.
  • Large community and support: Ansible benefits from a vast community and an abundance of resources and modules.
Ansible Installation
Inventory

The inventory file is a configuration document used by Ansible to list and organize the hosts and server groups on which tasks and playbooks will be executed.

Ansible communicates with remote nodes using SSH for Unix/Linux systems and WinRM for Windows systems, enabling secure and efficient management of configurations and automations remotely.

Ansible Ping

This command sends a ping to all the hosts defined in inventory.ini to verify that Ansible can connect to them correctly.

Playbooks

An Ansible playbook is a YAML file describing the tasks to be executed on the servers.

This playbook targets the server group in your inventory file and executes a task to install Apache on the machines in this group.

Tasks

Tasks are the basic units of action in an Ansible playbook. They define what you want to achieve on the targeted hosts.

This task updates the packages on an Ubuntu server using the apt module. Ansible has a wide range of modules for various tasks. For example, to manage files, use the file module.

Variables
Facts

Facts in Ansible are automatically generated variables containing information about remote systems. They are collected by Ansible each time it connects to a target host, providing details such as the operating system, IP addresses, available disks, etc.

Facts can be used in your playbooks to condition the execution of tasks based on the characteristics of the host.

Roles

Roles in Ansible organize tasks, files, templates, and variables into logical units, thereby facilitating reuse and management.

Ansible Vault

Ansible Vault is a tool integrated into Ansible that allows for the encryption of sensitive data files for security. It is particularly useful for managing sensitive information such as passwords or secret keys in your playbooks, roles, or variable files.

Ansible Vault Usage

To use encrypted variables in your playbooks, you must first include the encrypted secrets file. Use the vars_files directive in your playbook to specify the encrypted file.

Ansible Galaxy

Ansible Galaxy is a platform where the community shares reusable roles : https://galaxy.ansible.com/ui/

This playbook targets two groups of hosts: web servers for the Nginx role and DB servers for the MySQL role.

Errors

Sometimes, you may want to continue the execution of the playbook even if a task fails. You can use ignore_errors.

You can control the conditions under which a task is considered to have failed or succeeded by using failed_when and changed_when. Here, if the word “ERROR” is present, the task fails.

 

 

Leave a Comment