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
<managed_node_ip>
with the IP address of each managed node: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
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