DevOps - Lab 5: Installing Ansible Server

Installing Ansible Server

In Lab 5: Installing Ansible Server, participants typically concentrate on the installation and initial setup of Ansible, a powerful open-source automation tool. This lab involves installing the Ansible control node, which serves as the central server for managing configurations and orchestrating automation tasks. Participants may configure essential settings such as inventory files and connectivity parameters. Ansible, known for its simplicity and agentless architecture, allows users to control remote machines through SSH. The lab aims to provide hands-on experience in setting up the Ansible server, enabling participants to efficiently automate and manage configurations across their infrastructure. Successful completion of Lab 5 equips participants with the foundational skills needed to leverage Ansible as a versatile automation tool within their DevOps workflows.

Lab:

Step 1: Launch three Amazon-Linux-2 machines

Step 2: Download and install epel repository

wget http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum install epel-release-7.noarch.rpm –y
sudo yum update –y

Step 3: Install ansible along with git, python, python-devel, python-pip, openssl

sudo yum install git python python-devel python-pip openssl ansible –y

Step 4: Go inside ansible.cfg which is under /etc/ansible directory to enable or uncomment the below lines

vi /etc/ansible/ansible.cfg 
(Press i)
inventory = /etc/ansible/hosts                                 (uncomment)
sudo\_user = root                                                        (uncomment)
(Press esc)
:wq!

Step 5: Ansible inventory

vi /etc/ansible/hosts
(Press i)
\[groupname\]
machine name OR machine IP
(Press esc)
:wq!

Step 6: Test environment setup

adduser ansible                                                           (in all machines)
passwd ansible                                                            (in all machines)
visudo
(Press i)
ansible ALL=(ALL) NOPASSWD:ALL
(Press esc)
:wq!

Step 7: To establish ssh connection among all hosts (do it in all machines)

vi /etc/ssh/sshd\_config
(Press i)
PermitRootLogin yes		                                    (uncomment line, set to yes)
PasswordAuthentication yes	                            (uncomment line, set to yes)
PermitRootLogin no		                                    (comment)
PasswordAuthentication no	                            (comment)
(Press esc)
:wq!
service sshd restart
su ansible -
whoami
sudo yum update
ssh <node-private-ip>                                               (It prompts for password)

Step 8: Password less authentication (on Ansible Server)

ssh key-gen                                                                (can see .ssh/both keys in same directory)

Step 9: Copy the ssh keys to all the nodes (be in a master, be in a .ssh folder, will ask password for the last time)

ssh-copy-id ansible@<node-private-ip\>

Step 10: Test ssh connection

ssh <node-private-ip>