Pages

Monday, April 8, 2024

Setting Up Ansible on Ubuntu: A Step-by-Step Guide

Setting Up Ansible on Ubuntu: A Step-by-Step Guide


Preparing Your Ansible Environment

This guide walks you through the process of setting up Ansible for automation across multiple servers. We'll start by preparing the controller node, followed by setting up managed nodes, and then establish secure, password-less SSH communication between them.

Step 1: Setting Up the Controller Node (Server1)

First, update your package lists and install Ansible along with some essential packages on your controller or master node:

sudo apt update sudo apt install python3 ansible openssh-client vim iputils-ping -y

Step 2: Preparing Managed Nodes (Server-2, Server-3, and Server-4)

On each of your managed nodes, you'll need to install necessary packages for Ansible communication and management tasks:

sudo apt update; sudo apt install vim ssh python3 -y

Step 3: Establishing Password-less SSH Authentication

To allow the controller node to communicate with managed nodes without requiring password authentication, you'll set up SSH keys.

a) On your controller node (Server1), generate an SSH key pair if you haven't already:

 ssh-keygen

b) Copy the public SSH key to each managed node (Server-2, Server-3, and Server-4) to enable password-less authentication. Replace <managed_node_ip> with the IP address of each managed node:

ssh-copy-id root@<managed_node_ip>

For example:
ssh-copy-id root@172.19.0.79

Step 4: Configuring Root Privileges and SSH Settings on Managed Nodes

Ensure that each managed node is configured to allow SSH access and permit root login, which is necessary for Ansible tasks that require elevated privileges.

a) On each managed node, edit the SSH configuration:

vim /etc/ssh/sshd_config

Find and modify (or ensure) the following settings:

PermitRootLogin yes PasswordAuthentication yes

b) Restart the SSH service on each managed node to apply the changes:

service ssh restart

Step 5: Setting Root or User Passwords

Make sure each managed node has a set root (or user) password. This step is crucial if you need to manually log in for troubleshooting or other tasks.

Step 6: Test the connections:

Ansible all -m ping

Your Ansible environment is now ready!




No comments:

Post a Comment