Ansible Setup Installation & Playbook tests in Linux Virtual Machine LAB


As a pre-requisites for installation , configuration & testing ansible playbook on Linux virtual machine lab also refer Step by Step Linux VM LAB Setup on Virtual Box


In this article we will ...

1. Install ansible on controller linux machine (mylab-tmpl)

2. Configure SSH & hostname on controller  (mylab-tmpl) & target machine  (mylab-srv1)

3. Update inventory & perform ping , restart test using ansible commands / playbooks 


Lets begin ..


1. Install ansible on controller linux machine (mylab-tmpl)


1.1 install ansible packages on controller (mylab-tmpl)


apt install ansible




1.2 Verify ansbile version 


ansible --version




2. Configure SSH & hostname on controller  (mylab-tmpl) & target machine  (mylab-srv1)


2.1 Hostname / Reachability  

Update hostname / IP address on controller & target in each server
Perform ping test for reachability of nodes  

ping mylab-tmpl
ping mylab-srv1







2.2 SSH login configuration


configure controller (mylab-tmpl) & target (mylab-srv1) to login using ssh on each other

ssh root@mylab-tmpl
ssh root@mylab-srv1






3. Update inventory & perform ping , restart test using ansible commands / playbooks 


3.1 create inventory , perform ping test using ansible command

create a project directory for inventory & YAML playbook files

cat > inventory.lst
target ansible_host=<IP> ansible_ssh_pass=<pwd>

apt install sshpass

ansible target -m ping -i inventory.lst 




3.2 test ansible command for restart

ansible all -m reboot -i inventory
or
ansible target -m reboot -i inventory








3.3 Ping test using ansible playbook

  

root@mylab-tmpl:~/ansible-demo-prj# cat ansible-ping-test.yml

-

  name: "To Test Ping response of Target server"

  hosts: target

  tasks:

        -  name: "Ping Test"

           ping:

root@mylab-tmpl:~/ansible-demo-prj# ansible-playbook ansible-ping-test.yml -i inventory.lst








Also refer ..





No comments:

Post a Comment