Introduction
Ansible is an open-source automation tool that automates software provisioning, configuration management, and application deployment. It is designed to help manage and control a large number of servers from a centralized location. Ansible uses a simple, human-readable language called YAML to describe automation jobs, and it can communicate with a wide variety of systems, including Linux, Windows, and network devices. It is primarily used for IT operations such as configuration management, application deployment, task automation, and IT orchestration.
Requirement
- Basic knowledge of Linux commands
- Root permission
In this post, We will show you how to install Ansible on ubuntu 22.04 LTS
Step 1: Installing Ansible Dependencies
We need to update ubuntu default repository before installing the Ansible, Use the given command for the same.
sudo apt-get update && sudo apt-get install aptitude -y Step 2: Installing Ansible
To install the Ansible on ubuntu 22.04 LTS, We need to are good execute the given command.
To add ansible repository
sudo apt-add-repository ppa:ansible/ansible To install Ansible
sudo apt-get update && sudo apt-get install ansible -yTo verify Ansible version.
ansible --versionStep 3: Configure Python Interpreter
We need to make chnages in Ansiible's default hosts file, We need to add the following configuration.
To open the ansible's host file.
sudo nano /etc/ansible/hostsAdd the following syntax.
[all:vars]
ansible_python_interpreter=/usr/bin/python3Step 4: Disable Host Key Checking
To avoid any kind pre conformation while connecting with SSH, We need to disable to host key checking param in /etc/ansible/ansible.cfg, We need to use the given command for the same.
To open the /etc/ansible/ansible.cfg
sudo nano /etc/ansible/ansible.cfgFind out the [defaults] section and make the changes true to false with host_key_checking = false
[defaults]
host_key_checking = falseStep 5: Add Host with Ansible
We need to add the ansible host machine with Ansible server to automate the installation and configuration, Use the following steps one by one.
To open the /etc/ansible/hosts
sudo nano /etc/ansible/hostsAdd the Ansible node by updating the credentials, Can we use username, password, and PEM key configuration to create a group of the ansible nodes, such as WebServer, and add all of WebServer's nodes.
With username and password use the following configuration.
[WebServer]
192.168.1.10 ansible_connection=ssh ansible_ssh_user=<TYPE_USERNAME> ansible_ssh_pass=<TYPE_PASSWORD_HERE>With username and ssh key use the following configuration.
[WebServer]
10.10.10.11 ansible_user=<TYPE_USERNAME> ansible_ssh_private_key_file=/home/aftab/.ssh/rsa.pem- IP Address
- ansible_user
- ansible_ssh_private_key_file
- anisble_ssh_pass
Step 6: Testing Connection with Ansible
ansible -m ping allStep 7: Running Ad-Hoc Commands
While working with Ansible, we need to use the Ad-Hoc command from time to time. Here, we are going to use a few of the Ad-Hoc commands in order to use the real project.
To check memory.
ansible -a "free -m" allTo check disk space.
ansible -a "df -h" all 










