Learn Ansible and how to Install it in Ubuntu 22.04.
Tags: tutorial, install, dataengineering
Published: 2022-10-05 23:06:24

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
```

![Apt update](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hkn2zqdl005vv26vmqc2.png)




```
sudo apt install software-properties-common
```


![Install  properties command](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w8yrjhbcgsezpwucp2sn.png)


```
sudo add-apt-repository --yes --update ppa:ansible/ansible
```


![Add the PPA repository](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/99jc4om6kmuk215k6pva.png)


```
sudo apt install ansible
```


![Install ansible](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r8nnto3g1zelfado7sh0.png)



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


Conclusion.

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](https://twitter.com/deno_exporter) or [LinkedIn](https://www.linkedin.com/in/denis-mashellkinyungu-1b79bb171/) handles. It will be good to connect with you.