Ansible Ping Module Usage Level 2 Ansible KodeKloud Engineer Task Success

Ticker

6/recent/ticker-posts

Ansible Ping Module Usage Level 2 Ansible KodeKloud Engineer Task Success

  Question: The Nautilus DevOps team is testing Ansible playbooks on various servers within their stack. They've placed some playbooks under /home/thor/playbook/ directory on the jump host and now intend to test them on app server 2 in Stratos DC. However, an inventory file needs creation for Ansible to connect to the respective app. Here are the requirements:

a. Create an ini type Ansible inventory file /home/thor/playbook/inventory on jump host.

b. Include App Server 2 in this inventory along with necessary variables for proper functionality.

c. Ensure the inventory hostname corresponds to the server name as per the wiki, for example stapp01 for app server 1 in Stratos DC.

Note: Validation will execute the playbook using the command ansible-playbook -i inventory playbook.yml. Ensure the playbook functions properly without any extra arguments.

Please Note:-  Perform the below commands based on your question server,  user name & other details that might differ. So please read the task carefully before executing it. All the Best 👍


Solution:  

1Go through the folder mentioned in task and verified the inventory edit user

thor@jumphost ~$  ls -l /home/thor/ansible/

total 4

-rw-r--r-- 1 thor thor 180 Jul 13 07:35 inventory

thor@jumphost ~$ 

thor@jumphost ~$ cd /home/thor/ansible/

thor@jumphost ~$ vi inventory 

thor@jumphost ~/ansible$ cat inventory 

stapp01 ansible_host=172.16.238.10 ansible_ssh_pass=Ir0nM@n

stapp02 ansible_host=172.16.238.11 ansible_ssh_pass=Am3ric@

stapp03 ansible_host=172.16.238.12 ansible_ssh_pass=BigGr33n ansible_user=banner

thor@jumphost ~/ansible$ 


2.  Generate a SSH key on Jump Host . Please note it should Thor user 

  ( refer Video below for clarity )

thor@jumphost ~/ansible$   ssh-keygen -t rsa -b 2048

Generating public/private rsa key pair.

Enter file in which to save the key (/home/thor/.ssh/id_rsa): 

Enter passphrase (empty for no passphrase): 

Enter same passphrase again: 

Your identification has been saved in /home/thor/.ssh/id_rsa

Your public key has been saved in /home/thor/.ssh/id_rsa.pub

The key fingerprint is:

SHA256:5yqKC4NthOEadY6C76uaU80IP/tmkjJ1UHqqMpFhS80 thor@jumphost.stratos.xfusioncorp.com

The key's randomart image is:

+---[RSA 2048]----+

|                 |

|    .            |

|. +o.            |

|=*oE.            |

|B*+B.   S .      |

|=BB +    o       |

|==+=      .      |

|B*+.o .  .       |

|**=Bo. ..        |

+----[SHA256]-----+

thor@jumphost ~/ansible$ 

3.Copy SSH key to setup password-less authentication to the host mentioned in the task   


tthor@jumphost ~/ansible$ ssh-copy-id  banner@stapp03

/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/thor/.ssh/id_rsa.pub"

/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed

/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys

banner@stapp03's password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'banner@stapp03'"

and check to make sure that only the key(s) you wanted were added.

thor@jumphost ~/ansible$ 


4. validate the task by running the below command

thor@jumphost ~/ansible$ ansible stapp03 -m ping -i inventory 

stapp03 | SUCCESS => {

    "ansible_facts": {

        "discovered_interpreter_python": "/usr/bin/python3"

    },

    "changed": false,

    "ping": "pong"

}

thor@jumphost ~/ansible$ 


5. Click on Finish & Confirm to complete the task successful

Happy Learning!!!!


Apart from this if you need more clarity,  I have made a  tutorial video on this , please go through and share your comments. Like and share the knowledge

Post a Comment

0 Comments

Latest Posts

Ansible Ping Module Usage Level 2 Ansible KodeKloud Engineer Task Success