Install and configure ansible on ubuntu linux


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


To verify Ansible version.

ansible --version



Step 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/hosts


Add the following syntax.

[all:vars]
ansible_python_interpreter=/usr/bin/python3



Step 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.cfg


Find out the [defaults] section and make the changes true to false with host_key_checking = false

[defaults]
host_key_checking = false



Step 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/hosts


Add 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




We can use the above Ansible host configuration, and we need to replace the Ansible host credentials listed below:
  • IP Address
  • ansible_user
  • ansible_ssh_private_key_file
  • anisble_ssh_pass 


Step 6: Testing Connection with Ansible 

After adding your servers to the inventory file, it's time to see if Ansible can use SSH to connect to them and run commands.

Since the Ubuntu root account is typically the only account that is available by default on newly created servers, we will use it for this guide. You are encouraged to use the regular sudo user that has already been created on your Ansible hosts.

The remote system user can be specified with the -u argument. Ansible will attempt to connect to the control node as your current system user if this parameter is not provided.

To check ping with Ansible's node, Use the following command.

ansible -m ping all



Step 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" all



To check disk space.

ansible -a "df -h" all 




Conclusion

We have successfully Installed Ansible automation tool on Ubuntu 22.04 LTS. If you still have any questions, please leave a comment below:


Aftab Ali

My expertise is in ethical hacking, penetration testing, network security, monitoring and more.

Post a Comment (0)
Previous Post Next Post