Getting started with Ansible
Red Hat Ansible is an open source configuration management tool that we use for automating tasks, deploying applications, and IT infrastructure orchestration. Using Ansible, you can automate everyday tasks like updating and patching systems, installing software, onboarding users, and provisioning infrastructure.
In this first article, we’ll cover basic terminology, why to choose Ansible, and how to install it. In an upcoming article, we’ll look at how to configure Ansible.
Basic Ansible terminology
Before diving into Ansible, let’s get familiar with Ansible terminology.
Node terminology
Important node-related terminology for Ansible includes control nodes, managed nodes, inventories, and hostfiles:
- Control node: Any host with Ansible installed. Ansible control nodes are primarily used to run tasks on managed hosts. You can use any machine with Python installed as an Ansible control node. However, you cannot use Windows as an Ansible control node.
- Managed nodes: Hosts that you manage using Ansible.
- Inventory: A list of managed nodes.
- Hostfile: An inventory file is often known as a hostfile. In it, you can specify your inventory using IPs or hostnames and can organize them into groups.
Modules
Modules are code blocks that Ansible executes to perform common tasks like adding users, copying files, and pinging managed hosts.
Tasks and playbooks
Tasks are actions that Ansible performs on a managed host. You can perform a single task using ad-hoc commands.
Ansible playbooks are lists of repeatable tasks written in YAML Ain’t Markup Language (YAML), which makes them easy to read, write, and share.
Why Ansible?
When choosing a new tool, you’ll always have this question: "Why should I consider using this tool over others?" There are several reasons why you should use Ansible as your configuration management and infrastructure orchestration tool. Here are some of them.
Ansible is agentless
Unlike Chef and Puppet, Ansible is agentless, meaning that you don’t have to worry about installing or configuring any packages on your managed nodes. Since Ansible doesn’t install any software or run daemons on a managed node, there is no question on how to upgrade Ansible. This fact eliminates a lot of admin overhead and lets you start using Ansible in few hours, saving you time to work on playbooks.
Ansible uses SSH for communication
Ansible, by default, uses the SSH protocol for communication between control nodes and managed nodes. Ansible can then communicate securely with its managed nodes using SFTP for secure file transfers.
Ansible uses parallelism (forks)
Ansible communicates in parallel with its managed nodes, allowing it to run automated tasks much faster. By default, the forks
value is five, but this value can be altered in the configuration file.
Installing Ansible
To keep things simple in this series, I’ve created one control node named RHEL8
and four managed nodes (node1
, node2
, node3
, and node4
) all running Red Hat Enterprise Linux.
Ansible can be installed on any machine, but there are requirements for the control node. Control nodes should have Python 2 (2.7) or Python 3 (3.5 or higher) installed. Windows control nodes are not supported.
You can install Ansible from source code, the Python package manager (PIP), or your distro’s package manager. The recommended method for installing Ansible is from the distro’s package manager, so here we install Ansible on a Red Hat machine from its package manager, on our control node named RHEL8
:
[kc@RHEL8 ~]$ sudo yum install ansible -y
or:
[kc@RHEL8 ~]$ sudo dnf install ansible -y
Now, check the installed version of Ansible:
[kc@RHEL8 ~]$ ansible --version
ansible 2.8.5
config file = /etc/ansible/ansible.cfg
configured module search path = ['/home/kc/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.6/site-packages/ansible
executable location = /usr/bin/ansible
python version = 3.6.8 (default, Jun 12 2019, 01:12:31) [GCC 8.2.1 20180905 (Red Hat 8.2.1-3)]
Check back soon for another article to learn how to configure your new installation.
Keerthi Chinthaguntla
Keerthi is aspiring Cloud, DevOps engineer, he has been working with Windows and Linux systems. He believes in continuous learning (CL) and continuous sharing (CS), on his way building his very own CL CS pipeline. When he is not playing in the CLI, you will find him playing Cricket. More about me