LAB 5: Installing Ansible Server


LAB 5: Installing Ansible Server

Step 1: Launch three Amazon-Linux-2 machines

Step 2: Download and install epel repository

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)

Step 5: Ansible inventory

vi /etc/ansible/hosts
(Press i)
machine name OR machine IP
(Press esc)

Step 6: Test environment setup

adduser ansible                                                           (in all machines)
passwd ansible                                                            (in all machines)
(Press i)
(Press esc)

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)
service sshd restart
su ansible -
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>