DevOps

LAB 5: Installing Ansible Server

DevOps

LAB 5: Installing Ansible Server

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>