Latest Updates

Post Top Ad

24 August, 2021

Ansible Installation and Uses with Demo

    

Ansible Installation and Uses with Demo


Ansible is open source IT Configuration Management Tool, Deployment and Orchestration tool. It provides a large variety of automation possibilities. 

Ansible is available to RHEL, Debian, CentOs, Oracle Linux. RedHat acquired the ansible tool. RedHat developer Ansible Tower as an enterprise edition. 

In this blog, we will start from scratch on how to install and use Ansible on Amazon EC2 Machine.









Requirements:

  • Create 3 ec2 instances
  • Install ansible packages
  • Hosts and ansible configuration files
  • Add ansible user
  • Trust relationship & ssh connections across all nodes
  • Test ansible commands

Ansible Architecture


1. Create three ec2 instances

Launch three ec2 Linux machines. One ec2 machine will serve as an Ansible server. Other ec2 machines will act as nodes.





2. Install ansible packages


Once we access the ec2 machine. We will now install ansible packages on one EC2 Machine.

Command:
wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm


Command:
yum install epel-release-latest-7.noarch.rpm


Command:
yum update -y
yum install git python python-level python-pip openssl ansible -y



Command:
which ansible
ansible --version



3. Host and Ansible configuration file

Add private ips of nodes ec2 Linux machine to the host's file. 
Here we have created one demo group where we have added both nodes ips.

vi /etc/ansible/hosts



Edit the ansible configuration file and do the following changes and save

inventory      = /etc/ansible/hosts
sudo_user      = root

Command:
vi /etc/ansible/ansible.cfg





4. Add ansible user on all nodes( Ansible server and other nodes)

Command:
adduser ansible
passwd ansible

5. Trust relationship & ssh connections across all nodes


Command:
sudo su -
visudo

Add this line and save

## Allow root to run any commands anywhere
root    ALL=(ALL)       ALL
ansible ALL=(ALL) NOPASSWD: ALL

Follow the same on all nodes. Now test if from ansible user you get the sudo access or not.

Command:



Configure ssh connection from ansible servers to all nodes 

Command:
vi /etc/ssh/sshd_config

Make the changes based on below.

PermitRootLogin yes


# To disable tunneled clear text passwords, change to no here!
PasswordAuthentication yes
#PermitEmptyPasswords no
#PasswordAuthentication no




Restart the httpd services


Repeat these steps on all servers.

Now, from ansible user-run ssh-keygen command 



copy the key from Ansible server to all nodes using command

cd  
 ssh-copy-id ansible@172.31.0.17  (Node1 private ip)
 ssh-copy-id ansible@172.31.11.87 ( Node2 private ip)



From here passwordless ssh connection is established from ansible server to other nodes.



6. Test ansible commands


Command:
[ansible@ip-172-31-4-81 .ssh]$ ansible all --list


[ansible@ip-172-31-4-81 .ssh]$ ansible all -a "ls"


[ansible@ip-172-31-4-81 .ssh]$ ansible demo --list
  hosts (2):
    172.31.0.17
    172.31.11.87

here demo is a group added in the host's file and under which we have added two Linux nodes.

[ansible@ip-172-31-4-81 .ssh]$ ansible demo -a "ls -lrth"




List selected nodes from nodes.

[ansible@ip-172-31-4-81 .ssh]$ ansible demo[0] --list




Next blog we will see Ansible Adhoc commands.

Please Subscribe and Like

No comments:

Post Top Ad

Your Ad Spot

Pages