DEV Community

Cover image for Learn Ansible and how to Install it in Ubuntu 22.04.
Kinyungu Denis
Kinyungu Denis

Posted on

Learn Ansible and how to Install it in Ubuntu 22.04.

Greetings to my esteemed readers.

In this we will learn how to install Ansible in Ubuntu 22.04, also I will cover the details of Ansible so you are familiar with it.

What is Ansible and why should we use it?

Ansible refers to an open-source infrastructure automation tool that was initially developed by RedHat and is used to tackle all kinds of challenges that come with infrastructure as a code.

Ansible has three major kinds of uses.

  • Infrastructure automation
  • Configuration management
  • App Deployment

Infrastructure automation

The provisioning use case for using Ansible.
Using Ansible you can create an environment in the existing Infrastructure such as a Virtual Private Cloud (VPC) and your favorite cloud provider. Let us have that our VPC has four virtual machines.

Configuration management

The main use case is the ability to configure your actual infrastructure

The key principles in Ansible

It is declarative, use an Ansible playbook to group together a set of tasks that you need to run by procedurally keeping things.

Create an Ansible playbook, a book of tasks, or a set of plays.
A play has three main things:

  • The name of the play
  • The host that you will run against.
  • The actual tasks that will run

You will define the hosts that will be run against, and define a set of tasks such as security patching.
Ansible tasks.

The set of virtual machines will be the set of hosts, however, in the Ansible world, we call this an inventory. The set of hosts that Ansible can work on.

Ansible takes the advantage of YAML in writing configuration files and you can declare the tasks you want.

Ansible is agent-less, you do not need to install an agent on the Virtual Machines that you have provisioned.
Ansible takes advantage of a secure shell (SSH) to directly run the tasks in the virtual machines.

Ansible is idempotent, this is an operation that can be run multiple times without changing beyond the initial configurations.
It should recognize changes when run multiple times and what needs to be resolved to ensure every task has been done.

Ansible is community-driven, a lot of Ansible playbooks are availed by the community and published as collections, developers have a repository to contribute to.

App Deployment

Ansible can be used to deploy the actual web applications and workloads into virtual machines.

Now we have a basic understanding of Ansible, let us install it on our machine.

The command to ensure our terminal is up-to-date

sudo apt update
Enter fullscreen mode Exit fullscreen mode

Apt update

sudo apt install software-properties-common
Enter fullscreen mode Exit fullscreen mode

Install  properties command

sudo add-apt-repository --yes --update ppa:ansible/ansible
Enter fullscreen mode Exit fullscreen mode

Add the PPA repository

sudo apt install ansible
Enter fullscreen mode Exit fullscreen mode

Install ansible

The above commands will ease the process as you install Ansible in your Ubuntu 22.04.


We have learned the basics about Ansible and how to install it in Ubuntu 22.04.
I will be dropping more articles about how one uses Ansible.

Let me know what you think about this article through my Twitter or LinkedIn handles. It will be good to connect with you.

Top comments (0)

Regex for lazy developers

regex for lazy devs

You know who you are. Sorry for the callout 😆