DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Hardware-Accelerated OpenGL Rendering in a Linux Container
  • Spinnaker Meets Minikube: Part 1
  • LLM-Powered Deep Parsing for Industrial Inventory Search
  • Beyond Fail-Safe: Designing Fail-Operational State Machines for Physical AI

Trending

  • From 24 Hours to 2 Hours: How We Fixed a Broken BI System With Apache Airflow
  • GenAI Implementation Isn't Magic — It’s a Lifecycle
  • Stop Debugging Glue Jobs Manually: Building an Agentic Observability Layer for Data Pipelines
  • Stop Choosing Sides: An Engineering Leader's Framework for Build, Buy, and Hybrid AI Agents in 2026
  1. DZone
  2. Data Engineering
  3. AI/ML
  4. 10 Easy-to-Use Modules in Ansible

10 Easy-to-Use Modules in Ansible

Learn about the most common modules in Ansible playbooks, what they do, and how to use them.

By 
Sachin Slathia user avatar
Sachin Slathia
·
Oct. 31, 18 · Tutorial
Likes (4)
Comment
Save
Tweet
Share
32.7K Views

Join the DZone community and get the full member experience.

Join For Free

Ansible is all about using modules in its Playbook. This article talks about my top ten most used modules.

Before reading this blog, I would like to explain some terminologies used below.

  1. test-servers: the group of my hosts which I have written in my inventory file.
  2. - m XYZ: XYZ is the module name.
  3. -u ec2-user: defines username that is ec2-user.
  4. SUCCESS: means that my module has done its task on destination nodes.
  5. Changed: If it is true, something has changed on the destination nodes. If it is false, something has not changed on the destination nodes.

Let's start with the modules:

Ping Module

Ping is used when we want to check whether the connection with our hosts defined in the inventory file is established or not.

ansible test-servers -m ping -u ec2-user

ping changes to pong if an SSH connection is established.

Setup Module

The setup module is used when we want to see the information of all the hosts, their configuration, and detailed information.

ansible test-servers -m setup -u ec2-user

This is a snapshot of the configuration of my machine running on AWS.

Copy Module

The copy module is often used in writing playbooks when we want to copy a file from a remote server to destination nodes.

For example, suppose we want to copy a file from a remote server to all destination machines.

ansible test-servers -m copy -a 'src=/home/knoldus/Personal/blogs/blog3.txt dest=/tmp' -u ec2-user

Yum Module

We use the Yum module to install a service.

ansible test-servers -m yum -a 'name=httpd state=present' -become -u ec2-user

Apache2 will be installed on our machines.

The key point to note here is that we have to use -become, which is new in version 2.6; before, we had to use -s.

Shell Module*

When we want to run UNIX commands then we use shell module

ansible test-servers -m shell -a 'ls -la' -u ec2-user

https://gist.github.com/slathia15/be3f84fa101ab39fb0d1969b8a99fe5d

This will display all the files present in our machine with their permissions.

Service Module

When we want to ensure the state of a service that is service is running we use the service module.

ansible test-servers -m service -a 'name=httpd state=started' -become -u ec2-user

https://gist.github.com/slathia15/339cc8f6784bdec5037481f7dc225bbb

Apache2 is up on my machine.

Debug Module

To print a msg on hosts we use Debug module.

ansible test-servers -m debug -a 'msg=Hello' -u ec2-user

https://gist.github.com/slathia15/d408ac54c5cc1cddbf07d6b14abcaa3b

Hello, a message is printed on my machine.

Template Module

The Template module is used to copy a configuration file from the local system to the host server. It is the same as the copy module, but it dynamically binds group variables defined by us.

Here, I have vars in my source machine.

Include Module

When we want to include another playbook in our playbook, then we use the Include module.

User Module

To add a particular user to our module we can use User module. Here, we have added a user named Sachin to our module.

I hope this blog was useful. For more Ansible modules, we can refer to the documentation.

Ansible (software) Host (Unix) Machine Template Debug (command) Inventory (library) remote

Opinions expressed by DZone contributors are their own.

Related

  • Hardware-Accelerated OpenGL Rendering in a Linux Container
  • Spinnaker Meets Minikube: Part 1
  • LLM-Powered Deep Parsing for Industrial Inventory Search
  • Beyond Fail-Safe: Designing Fail-Operational State Machines for Physical AI

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook