Redhat Ansible is one of the most popular automation platforms in the IT industry. Since its launch, it has earned its place among some of the best DevOps tools. Powered by an open source community of more than 3550 contributors, it occupies more than 50% of the market share in the configuration management segment.
This article will explore Ansible and how IT professionals and engineers use it to power their workflows.
Read on to learn more about one of the most powerful automation platforms.
What is Ansible?
Ansible is an open-source automation platform that can be used to manage large groups of computer systems. It helps you automate application deployment, configuration management, cloud provisioning, updating workstations and servers, and many other tasks.
Ansible works on Windows and Unix systems and is included as part of the Fedora distribution. But machines used to execute the automation — referred to as control nodes — have to be Unix/Linux systems. You can use Windows machines, but with a Windows Subsystem for Linux distribution.
One of the most exciting aspects of Ansible is that it works agent-less unlike most other configuration management solutions. It doesn’t require remote systems with a specific agent or software to make changes or execute commands.
Benefits of Ansible
Ansible provides DevOps engineers with four clear benefits:
- It reduces the resources needed for managing IT - Sysadmins can contain hundreds or even thousands of machines from a single point and in a single go.
- It makes automation accessible - One of the design goals of Ansible was that minimal learning should be required to use it. The platform uses YAML(Yet Another Markup Language), a human-readable language with elements from other common programming languages.
- The Ansible platform doesn't affect performance - Ansible doesn’t require agents or software running or installed in managed systems. Because of this, managed systems don’t need to spend computational resources on Ansible.
- It ensures consistency - The platform was designed to be minimal and enable users to create consistent environments. And the entire operation is carried over an SSH connection means the forum doesn’t add more complexity to the systems.
How does Ansible work?
Ansible works by executing ‘Modules’ or code in target machines referred to as managed nodes. Modules, once executed, are removed from the target systems. These Modules can be for anything from copying a file to a remote machine and creating a compressed archive of files to managing VLAN interfaces.
In Ansible, a Task is a simple action applied to target machines. Tasks use Modules to execute an action on a remote device.
These Tasks are further rolled into an ordered list in a Play. A Play defines which all tasks are applied to which all machines.
Ansible playbooks
All the Plays are combined to form what’s called a Playbook. This is where users write all Ansible code.
The Ansible playbook is executed on a control node, and the Plays are executed in the order in which it is written. The Tasks within the Plays are, in turn, performed similarly. When executing a Task, the control node sends the respective Modules to all the target machines (managed nodes) mapped to the task.
Ansible Modules or, in turn, Ansible Playbooks are generally idempotent. This means that before the Module is executed, it checks if the managed node is already at the desired state. If so, no action is performed there.
Ansible ad hoc commands
Ansible ad hoc commands are used to execute a single command on many different machines. They are used to reboot servers, manage files, services, and packages, and gather facts. Ad hoc helps you avoid writing an entire Playbook for executing a small task once.
Ansible installation on Linux, RedHat, and Windows
Before installing Ansible, ensure your system has Python 3.8 or higher. If not, install that first.
How to install Ansible on Linux
The exact steps to install Ansible vary with different Linux distros. In this example, we’ll explain how you can install Ansible on Ubuntu.
Go to the terminal and update the apt package manager with the following command:
sudo apt update
In the next step, enter the following command:
sudo apt upgrade
This command updates all the outdated packages and dependencies on your system. You’ll see the following screen.
Now, hit "y", and then hit enter. The next step is installing some prerequisites to run Ansible on your system. For this, we need to install the package software properties common. Use the command:
sudo apt software-properties-common
You’ll see a screen that looks like this:
The following command installs the Ansible repository on your system.
sudo apt-add-repository --yes --update ppa:ansible/ansible
The screen should look like this once the command is executed.
The next step is to install Ansible. Use the following command for this:
sudo apt install ansible
You’ll get a screen that looks like this:
Hit y; hit enter, and Ansible will be installed.
To confirm installation, use the following command that checks the Ansible version. You should get a screen that looks like this.
How to install Ansible on Windows
Installing Ansible on Windows is the same as installing it in Ubuntu. But first, you need to install Windows Subsystem for Linux (WSL). This lets you run a Linux environment on your Windows system without any complications of dual booting.
To install WSL, open PowerShell and enter the command:
wsl --install
Then simply follow the on-screen commands.
By default, Ubuntu is installed. The Ubuntu Terminal will open up and ask you to set up a username and password.
Alternatively, you can use the following command to install a specific Linux distro. The below command installs Ubuntu:
wls --install -d ubuntu
To install Debian, you can use the following command:
wsl --install -d debian
Once you’ve added your user name and password, the rest of the steps are exactly as described in the above section.
How to install Ansible on RedHat
To use Ansible on Redhat, you need to install Python 3. In most cases, Redhat distros come installed with Python 3, but if not, you’ll have to install it.
The next step is to install pip with the following command:
$ sudo dnf install python3-pip
The next step is to enable the Ansible engine repository:
# subscription-manager repos --enable ansible-2.8-for-rhel-8-x86_64-rpms
Then install Ansible:
# dnf -y install ansible
How is Ansible used in DevOps?
DevOps is all about faster development and deployment by combining software development and IT operations. It encourages teams to use automation to get quick results; Ansible is one of the most commonly used tools.
One of the core parts of DevOps is CI/CD, which is one aspect Ansible can help with. Once an application is developed locally, the DevOps team can push this to the cloud along with an Ansible Playbook. The application work in the cloud as it did in the local.
Ansible works across many standard DevOps tools like Jira, ServiceNow, Github, Selenium, Jenkins, Containers, Nagios, and more. You can build Ansible Playbooks around these tools.
Ansible alternatives
While Ansible continues to be the market leader in automation and configuration management, it’s not due to a lack of competition. Here are some of the top alternatives for Ansible.
Ansible vs. Puppet
The main difference between Ansible and Puppet is that the former doesn’t need agents to work, meaning that you'll need to install a Puppet client on the target machines to use Puppet. So, this makes Puppet more challenging to get started with compared to Ansible.
Another difference is that Ansible uses YAML, while Puppet uses its declarative language called Puppet DSL. Generally, YAML is considered easier to learn compared to Puppet.
However, when it comes to GUI, Puppet has the upper hand. Ansible was initially designed as a command-line tool, and while it does have a GUI now, it's not as interactive as Puppet’s.
Ansible vs. Terraform
Ansible and Terraform are agentless; you don’t need to install anything in the target machines or systems to use them. And because of this, you can use them on newly created virtual machines.
While both do similar jobs, Ansible is viewed as a configuration management tool, while Terraform is an orchestration tool. In a massive oversimplification, Ansible is focused more on the nitty-gritty of an environment and trying to fix things, whereas Terraform is more about the big picture and replaces items when they don’t work.
Furthermore, in Terraform, configuration files are written in HCL (Hashicorp Configuration Language) syntax. The Terraform approach is described as declarative in contrast with the procedural process of Ansible.
Ansible vs. Chef
Chef works with a master-slave system, with agents installed in the target system, unlike Ansible, which works agentless.
Another (minor) difference between Ansible and Chef is that in Chef, the configuration files are referred to as Cookbooks, while in Ansible, they’re referred to as Playbooks.
Chef also uses Ruby DSL, unlike Ansible, which uses YAML. The latter is much easier to learn compared to Ruby DSL, which is more developer oriented.
Ansible vs. Jenkins
While Ansible is Python, Jenkins is built on Java, conferring an advantage to Jenkins. Plus, it is available on almost all operating systems, including macOS and Windows, and the only requirement is Java.
While there’s a lot of overlap in functionality between the two, Jenkins is viewed more as a continuous integration tool. And Jenkins works with master-slave architecture.
Key takeaways
Ansible is one of the most common automation tools used in DevOps. It uses configuration files called Playbooks written in YAML. Playbooks are composed of Plays, and the individual Tasks are executed similarly. The actions in a Task are executed by Ansible Modules, which are binary codes for performing a small step in the target machines.
There are two types of systems or nodes in Ansible, control nodes and managed nodes. When a Playbook is executed, the control nodes send Modules to the managed nodes over an SSH connection (by default).
Frequently Asked Questions
What is Ansible used for?
Ansible is used for automating IT operations such as deploying applications, managing configurations, scaling infrastructure, and other activities involving many repetitive tasks.
What is the latest Ansible version?
Ansible 2.9
How much does Ansible cost?
Red Hat offers two plans for Ansible; Standard and Premium. Standard comes with 8x5 support, while the premium provides 24x7 support. Various sources suggest an annual fee of $10,000 for Standard and $14,000 for Premium. Both plans support 100 nodes.
How to patch Linux servers using Ansible?
You can use the YUM Module for patching Linux servers. YUM is a package manager with which you can install, upgrade, downgrade, remove, or list packages.