Skip to main content

Command Palette

Search for a command to run...

Day 82: Create Ansible Inventory for App Server Testing | 100 Days of DevOps

Updated
โ€ข4 min read
R
Iโ€™m currently working in DevOps and documenting my learning journey along the way. From CI/CD pipelines to cloud and containers, Iโ€™m exploring how modern systems are built and deployed. This blog is where I share what I learn, break down concepts in simple terms, and track my progress. Learning one concept at a time, and trying to apply it practically.

Content

Today I worked on creating an Ansible inventory file for testing playbooks on a remote application server. This task helped me understand how Ansible inventories define target hosts, how connection variables are configured, and how Ansible uses inventory information to connect to remote systems without requiring additional command-line arguments.


๐Ÿ”น What I Learned

  • Understanding the purpose of an Ansible Inventory
  • Difference between Inventory and Playbook
  • Configuring remote host connection variables
  • Using inventory hostnames and host variables
  • Testing Ansible connectivity using the ping module
  • Running ad-hoc Ansible commands against specific hosts

๐Ÿ”น Task Requirement

As per the Nautilus DevOps team requirements, I needed to:

Create an Ansible inventory file with the following specifications:

Requirement Value
Inventory Type INI
Inventory Location /home/thor/playbook/inventory
Target Server App Server 3
Inventory Hostname stapp03
User banner
Password BigGr33n
Validation Command ansible-playbook -i inventory playbook.yml

The inventory needed to allow Ansible to connect successfully to App Server 3 without passing any additional arguments.


๐Ÿ”น Steps I Followed

1. Connected to the Jump Host

Logged into the jump host where the Ansible playbook was already available.

Executed:

cd /home/thor/playbook

Verified the existing files:

ls

Output:

ansible.cfg  playbook.yml

2. Reviewed the Existing Playbook

Executed:

cat playbook.yml

Observed:

---
- 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

This playbook installs and starts the Apache HTTP server on all hosts provided by the inventory.


3. Created the Inventory File

Created the inventory file:

vi inventory

Added the following host entry:

stapp03 ansible_host=stapp03 ansible_user=banner ansible_password=BigGr33n

Saved and exited the file.


๐Ÿ”น Simple Explanation of the Inventory Entry

Inventory Hostname

stapp03

This is the inventory hostname.

The task specifically required using the hostname corresponding to App Server 3.


Host Connection Address

ansible_host=stapp03

Specifies the address Ansible should connect to.

In this environment, the hostname itself was resolvable.


SSH User

ansible_user=banner

Defines the remote user Ansible uses for authentication.


SSH Password

ansible_password=BigGr33n

Provides the password required for remote login.


Complete Inventory Entry

stapp03 ansible_host=stapp03 ansible_user=banner ansible_password=BigGr33n

๐Ÿ‘‰ In simple terms:

This inventory entry tells Ansible:

  • Which server to manage
  • How to connect to that server
  • Which user account to use
  • What password to authenticate with

4. Verified Inventory Connectivity

Executed:

ansible all -i inventory -m ping

Observed:

stapp03 | SUCCESS => {
    "changed": false,
    "ping": "pong"
}

This confirmed:

  • Inventory file was valid
  • Hostname resolution worked
  • Authentication was successful
  • Ansible could communicate with App Server 3

5. Additional Validation

Executed:

ansible stapp03 -i inventory -m ping

This targeted only App Server 3 and confirmed connectivity.

Executed:

ansible stapp03 -i inventory -m command -a "hostname"

This executed a remote command and verified that Ansible was connecting to the correct server.


๐Ÿ”น Understanding Inventory vs Playbook

One important concept I learned during this task is the difference between Inventory and Playbook.

Inventory

Defines:

  • Where tasks run
  • Hostnames
  • Connection details
  • Authentication variables

Example:

stapp03 ansible_host=stapp03 ansible_user=banner ansible_password=BigGr33n

Playbook

Defines:

  • What tasks should be executed

Example:

hosts: all

Since the inventory contained only one host, all referred only to App Server 3.


๐Ÿ”น My Understanding

This task strengthened my understanding of how Ansible separates infrastructure information from automation logic.

The inventory tells Ansible where to connect, while the playbook defines what actions should be performed on the target systems.


๐Ÿ”น What I Found Interesting

I found it interesting that the playbook never explicitly mentioned App Server 3. Instead, Ansible dynamically determined the target host from the inventory file.

๐Ÿ“Œ Full notes: GitHub link

100_days_of_devops

Part 1 of 50

Documenting my 100 Days of DevOps journey with hands-on practice from KodeKloud, along with notes, commands, and mini projects