Day 87: Install Packages on App Servers using Ansible | 100 Days of DevOps
Content
Today I worked on an Ansible automation task that involved installing a software package on multiple application servers in the Stratos Datacenter. This exercise helped me understand how Ansible automates package management across multiple remote hosts using the yum module, how inventories simplify server management, and how playbooks can consistently install packages with a single command.
๐น What I Learned
- Creating and configuring an Ansible inventory file
- Managing multiple remote servers using inventory groups
- Installing software packages using the Ansible yum module
- Executing Ansible playbooks across multiple servers
- Validating package installation after automation
๐น Task Requirement
As per the Nautilus DevOps team requirements, I needed to:
- Create an inventory file:
/home/thor/playbook/inventory
and add all application servers as managed nodes.
- Create an Ansible playbook:
/home/thor/playbook/playbook.yml
to install the sqlite package on all application servers using the yum module.
- Ensure the thor user can successfully run the playbook on the jump host.
The solution must work using:
ansible-playbook -i inventory playbook.yml
without requiring any additional arguments.
๐น Steps I Followed
1. Navigated to the Working Directory
I first moved to the Ansible working directory on the jump host.
cd /home/thor/playbook
This directory would contain both the inventory file and the playbook.
2. Created the Inventory File
Opened the inventory file:
vi inventory
Added the following configuration:
[app_servers]
stapp01 ansible_host=stapp01 ansible_user=tony ansible_ssh_pass=Ir0nM@n
stapp02 ansible_host=stapp02 ansible_user=steve ansible_ssh_pass=Am3ric@
stapp03 ansible_host=stapp03 ansible_user=banner ansible_ssh_pass=BigGr33n
[app_servers:vars]
ansible_ssh_common_args='-o StrictHostKeyChecking=no'
Saved the file.
๐น Understanding the Inventory
Inventory Group
[app_servers]
Creates a group named app_servers.
Instead of targeting each server individually, Ansible can execute the playbook on every server in this group.
Managed Hosts
stapp01
stapp02
stapp03
These are the three application servers managed by Ansible.
Authentication Variables
Example:
ansible_user=tony
ansible_ssh_pass=Ir0nM@n
These variables tell Ansible:
- Which user account to connect with
- Which password to use for SSH authentication
Group Variables
ansible_ssh_common_args='-o StrictHostKeyChecking=no'
Normally, SSH asks for confirmation before connecting to a host for the first time.
This option disables that prompt so Ansible can connect automatically during automation.
Complete Inventory
[app_servers]
stapp01 ansible_host=stapp01 ansible_user=tony ansible_ssh_pass=Ir0nM@n
stapp02 ansible_host=stapp02 ansible_user=steve ansible_ssh_pass=Am3ric@
stapp03 ansible_host=stapp03 ansible_user=banner ansible_ssh_pass=BigGr33n
[app_servers:vars]
ansible_ssh_common_args='-o StrictHostKeyChecking=no'
๐ In simple terms, this inventory tells Ansible:
- Which servers to manage
- Which user to log in as on each server
- Which password to use
- Which hosts belong to the app_servers group
- To automatically accept SSH host keys
3. Verified Connectivity
Before creating the playbook, I tested connectivity to all application servers.
ansible app_servers -i inventory -m ping
Output:
stapp01 | SUCCESS => {
"ping": "pong"
}
stapp02 | SUCCESS => {
"ping": "pong"
}
stapp03 | SUCCESS => {
"ping": "pong"
}
๐น Why This Step Is Important
Running the ping module confirms that:
- The inventory is configured correctly
- SSH authentication works
- All servers are reachable
- Python is installed on the remote systems
Verifying connectivity first helps avoid troubleshooting during playbook execution.
4. Verified the Initial State
Before installing SQLite, I connected to one application server to confirm that the package was not already installed.
ssh tony@stapp01
Checked the package:
yum list installed sqlite
Output:
Error: No matching Packages to list
Observation
SQLite was not installed initially.
This established the baseline before running the automation.
After checking, I returned to the jump host.
5. Created the Playbook
Opened the playbook:
vi playbook.yml
Added the following content:
---
- name: install sqlite package on all app servers.
hosts: app_servers
become: true
tasks:
- name: install sqlite package
yum:
name: sqlite
state: latest
Saved the file.
๐น Understanding the Playbook
Target Hosts
hosts: app_servers
The playbook executes on every host inside the app_servers inventory group.
These include:
- stapp01
- stapp02
- stapp03
Privilege Escalation
become: true
Installing packages requires administrative privileges.
become: true allows Ansible to execute the task with elevated permissions, similar to using sudo.
Yum Module
yum:
The yum module manages software packages on RPM-based Linux distributions.
It can install, remove, or update packages automatically.
Package Name
name: sqlite
Specifies the package to install.
Package State
state: latest
This tells Ansible to ensure the latest available version of SQLite is installed.
If the package is:
- Missing โ Install it
- Outdated โ Upgrade it
- Already up to date โ Do nothing
This demonstrates Ansible's idempotent behavior.
6. Verified File Ownership and Permissions
Before running the playbook, I verified that the required files existed and were owned by the thor user.
Executed:
ls -la
Output:
total 20
drwxr-xr-x 2 thor thor 4096 Jun 26 18:20 .
drwx------ 1 thor thor 4096 Jun 26 18:20 ..
-rw-r--r-- 1 thor thor 308 Jun 26 18:18 inventory
-rw-r--r-- 1 thor thor 183 Jun 26 18:20 playbook.yml
๐น Why This Step Is Important
The task specifically states:
"Make sure user thor should be able to run the playbook on jump host."
This verification confirms that:
- Both inventory and playbook.yml exist.
- They are owned by the thor user.
- The files have appropriate read permissions.
- The thor user can execute the playbook without requiring additional permission changes.
Although the files were created by thor and therefore already owned by that user, verifying ownership and permissions ensures the task requirement is satisfied before execution.
7. Executed the Playbook
Ran:
ansible-playbook -i inventory playbook.yml
Output:
PLAY [install sqlite package on all app servers.]
TASK [Gathering Facts]
ok: [stapp01]
ok: [stapp02]
ok: [stapp03]
TASK [install sqlite package]
changed: [stapp01]
changed: [stapp02]
changed: [stapp03]
PLAY RECAP
stapp01 : ok=2 changed=1 failed=0
stapp02 : ok=2 changed=1 failed=0
stapp03 : ok=2 changed=1 failed=0
๐น Understanding the Output
Gathering Facts
TASK [Gathering Facts]
Before executing any tasks, Ansible collects system information such as:
- Hostname
- Operating system
- Network configuration
- Python interpreter
- Architecture
This information helps Ansible execute tasks appropriately on each host.
Package Installation Task
changed
The changed status indicates that Ansible successfully modified each server by installing the SQLite package.
Play Recap
ok=2
changed=1
failed=0
Meaning:
- Two tasks completed successfully
- One task modified the system
- No failures occurred
All three servers completed successfully.
8. Validated the Installation
After the playbook completed, I connected back to one application server.
ssh tony@stapp01
Verified the package installation:
yum list installed sqlite
Output:
Installed Packages
sqlite.x86_64 3.34.1-10.el9 @appstream
๐น Verification
โ SQLite package successfully installed
โ Package available through the system package manager
โ Playbook executed successfully on all application servers
โ Task requirement fulfilled
๐น My Understanding
This task helped me understand how Ansible automates software installation across multiple servers using the yum module. I also learned the importance of configuring the inventory correctly, verifying connectivity before deployment, and ensuring the playbook can be executed by the required user.
๐น What I Found Interesting
I found it interesting that a single Ansible playbook was able to install the sqlite package on all three application servers simultaneously. With just one command, Ansible handled remote connections, privilege escalation, and package installation consistently across every server.
๐ Full notes: GitHub link
- #install-packages-on-app-servers-using-ansible
- #install
- #package
- #yum
- #ansible
- #ansible-playbook
- #ansible-automation
- #ansible-package
- #ansible-adhoc
- #ansible-inventory-file
- #ansible-project
- #ansible-devops
- #ansible-article
- #devops
- #devops-articles
- #devops-journey
- #devopscommunity
- #devops-trends
- #devops-tools
- #devops-engineer
- #devopsculture
- #devopsjourney
- #devopsproject
- #100daysofdevops
About the author
- 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.
Comments
Join the discussionNo comments yet. Be the first to comment.
100_days_of_devops
Documenting my 100 Days of DevOps journey with hands-on practice from KodeKloud, along with notes, commands, and mini projects