Understanding Ansible Modules
As I continued learning Ansible, one of the most important concepts I came across was Modules.
They are the core of how Ansible performs automation. Once I understood modules clearly, writing playbooks and running ad-hoc commands became much easier and more meaningful.
In this blog, I’m sharing what Ansible modules are and how I understood them through hands-on practice.
⭐ What Are Ansible Modules? (In My Own Words)
Modules are the actual actions Ansible performs on a server.
If I want to:
-
install a package
-
create a file
-
add a user
-
start a service
-
copy a configuration
Ansible uses a module to do it.
So for me:
“Modules are the building blocks of every automation task in Ansible.”
Every ad-hoc command and every task inside a playbook uses a module.
⭐ How I Understand the Working of Modules
Whenever I run Ansible:
-
Ansible connects to the server through SSH
-
The selected module runs on the remote machine
-
It performs the action I defined
-
It returns the output back to Ansible in JSON
-
Ansible shows the task result (changed, ok, failed, skipped)
I don’t need to install anything on the target server — modules run automatically when executed.
⭐ Types of Modules I Found Most Useful
1. Package Management Modules
Used for installing or removing packages.
-
apt→ Ubuntu/Debian -
yum→ CentOS/RHEL
Example:
2. Service Modules
Used for managing services.
3. File & Directory Modules
These helped me with permissions, copying files, and modifying config files.
copy
file
lineinfile
4. User Module
For managing users:
5. Command & Shell Modules
When I needed to run basic Linux commands:
command
shell
(Shell supports pipes, redirects, etc.)
⭐ How I Used Modules in Ad-Hoc Commands
These commands helped me learn modules quickly without writing a playbook.
Ping
Install a package
Copy a file
Modules made it easy to run small tasks instantly.
⭐ How I Used Modules in Playbooks
Every task inside a playbook uses a module.
Example playbook:
Here I used three modules: apt, service, and copy.
This made automation smooth and predictable.
⭐ Why Modules Are Important (My Realisation)
After working with multiple modules, one thing became very clear:
Modules are the heart of Ansible.
Without modules, there is no automation.
They define what Ansible does, how it does it, and how consistent the results are.
⭐ Final Thoughts
Understanding modules helped me a lot in building confidence with Ansible. Once the concept clicked, writing tasks and playbooks became much easier and more enjoyable.
Next, I’ll write about:
👉 Ansible Installation & EC2 Setup
(where I installed Ansible and connected it to my EC2 instances)
Comments
Post a Comment