Create Ansible Inventory for App Server Testing Level 1 Ansible KodeKloud Engineer Task

Ticker

6/recent/ticker-posts

Create Ansible Inventory for App Server Testing Level 1 Ansible KodeKloud Engineer Task

 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:  

1. Go through the folder mentioned in the task and verified the playbook and files existing

thor@jump_host ~$ ls -l /home/thor/playbook/

total 8

-rw-r--r-- 1 thor thor  36 Sep 28 07:04 ansible.cfg

-rw-r--r-- 1 thor thor 250 Sep 28 07:04 playbook.yml

thor@jump_host ~$

thor@jump_host ~$ cat  /home/thor/playbook/playbook.yml

---

- hosts: all

  become: yes

  become_user: root

  tasks:

    - name: Install httpd package   

      yum:

        name: httpd

        state: installed

   

    - name: Start service httpd

      service:

        name: httpd

        state: started

thor@jump_host ~$


2.  Create an inventory file and add the app server as per your task.

     (Refer to your task and add app server in inventory )

thor@jump_host ~$ cd /home/thor/playbook/

thor@jump_host ~/playbook$ vi inventory

thor@jump_host ~/playbookcat /home/thor/playbook/inventory

stapp02 ansible_host=172.16.238.11 ansible_ssh_pass=Am3ric@  ansible_user=steve

thor@jump_host ~$


3.  Post file saved, run below command to execute the playbook 

thor@jump_host ~/playbook$ ansible-playbook  -i inventory playbook.yml

 

PLAY [all] *************************************************************************************************************************************************************

 

TASK [Gathering Facts] *************************************************************************************************************************************************

ok: [stapp02]

 

TASK [Install httpd package] *******************************************************************************************************************************************

changed: [stapp02]

 

TASK [Start service httpd] *********************************************************************************************************************************************

changed: [stapp02]

 

PLAY RECAP *************************************************************************************************************************************************************

stapp02                    : ok=3    changed=2    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0  

 

thor@jump_host ~/playbook$



4.  Click on Finish & Confirm to complete the task successfully

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

Create Ansible Inventory for App Server Testing  Level 1 Ansible KodeKloud Engineer Task