- yum update -y
- rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm (On Redhat image)
- yum install ansible -y (On Amazon Linux image)
- amazon-linux-extras install ansible2
- ansible --version
##Create ansadmin user and update its password
useradd ansadmin
passwd ansadmin
##Add ansadmin user to sudoers group
echo "ansadmin ALL=(ALL) ALL" >> /etc/sudoers
##sed command replaces "PasswordAuthentication no to yes" without editing sshd_config file
sed -ie 's/PasswordAuthentication no/PasswordAuthentication yes/' /etc/ssh/sshd_config
##create ssh keys for password-less authentication between Ansible control server and hosts.
#Login as ansadmin user and generate ssh key on Master
ssh-keygen
#Create same ansadmin user on the target host server.
#Copy Master ssh keys onto all ansible hosts nodes
ssh-copy-id <target-host-server>
#Update target servers IP on /etc/ansible/hosts file on Master (Always use internal Private IP address)
echo "<target host server IP>" >> /etc/ansible/hosts
Ansible hosts file should look like: cat /etc/ansible/hosts
[web-servers]
10.0.1.20
10.0.1.21
10.0.1.22
#Run ansible command as ansadmin user on Control server. It should be successful.
ansible all -m ping
We have now setup a successful passwordless authentication between all the hosts and the control server from where we can handle any type of tasks like installing any application, starting/stopping any service, copying a config file on servers.
This we will discuss in our next blog.
#Run ansible command as ansadmin user on Control server. It should be successful.
ansible all -m ping
We have now setup a successful passwordless authentication between all the hosts and the control server from where we can handle any type of tasks like installing any application, starting/stopping any service, copying a config file on servers.
This we will discuss in our next blog.
No comments:
Post a Comment