Install Ansible on Ubuntu

Introduction

Ansible is an open-source automation tool that simplifies IT operations such as configuration management, application deployment, and task automation. In this guide, we’ll walk through how to:

  • Install Ansible on an Ubuntu Control Node
  • Set up an Ubuntu Target Node
  • Establish passwordless SSH connectivity
  • Run your first Ansible command

Key Features:

  1. Agentless: Ansible does not require any agent software to be installed on the nodes it manages. It uses SSH for communication.
  2. Easy to Learn: Ansible uses a simple syntax written in YAML called playbooks.
  3. Idempotency: Ansible ensures that changes are applied only when necessary, making it safe to run multiple times without causing unintended effects.
  4. Extensible: Ansible modules can be written in any language that can return JSON.
  5. Scalable: Ansible can manage small environments to large-scale deployments.

Python must be installed on both the control node and the managed (target) nodes before you install and use Ansible.

Step 1: Install Ansible on the Control Node

🔹 1. Update Your System

sudo apt update
sudo apt upgrade -y

🔹 2. Add Ansible Repository

sudo apt install software-properties-common -y
sudo add-apt-repository --yes --update ppa:ansible/ansible

🔹 3. Install Ansible

sudo apt install ansible -y

🔹 4. Verify Installation

ansible –version

Step 2: Set Up SSH Access to the Target Node

Ansible connects to target machines using SSH. For this, we’ll set up key-based authentication.

🔹 1. Generate an SSH Key on the Control Node

ssh-keygen

Keep pressing Enter to accept default options. This creates:

  • Private key: ~/.ssh/id_rsa
  • Public key: ~/.ssh/id_rsa.pub

🔹 2. Copy the SSH Key to the Target Node

$ ssh-copy-id username@target_node_ip

Example:

$ ssh-copy-id ubuntu@192.168.1.8

🔹 3. Test SSH Connection

$ ssh ubuntu@192.168.1.8

📁 Step 3: Configure the Ansible Inventory File

🔹 1. Open Inventory File

$ sudo nano /etc/ansible/hosts

🔹 2. Add Target Node Entry

[target_nodes]

192.168.1.20 ansible_user=ubuntu

🧪 Step 4: Test Ansible Connection to the Target Node

$ ansible target_nodes -m ping

output:

192.168.1.8 | SUCCESS => {

"changed": false,

"ping": "pong"

}
Mahesh Wabale
Latest posts by Mahesh Wabale (see all)

Leave a Comment