Ansible Tutorial

Ansible Tutorial for Beginners

April 1st, 2026
3865
15:00 Minutes

If you've ever felt overwhelmed managing multiple servers or repeating the same tasks over and over, you're not alone. Professionals in roles like a system administrator, DevOps engineer, or those new to IT automation, Ansible is a powerful tool that can make your life a whole lot easier. This Ansible tutorial covers the basics of using Ansible for IT automation involving configuration management, orchestration and application deployment.

It will break down what Ansible is, how to install it, and how you can start using it right away - even if you're a complete fresher. No fluff, no jargon - just clear, practical guidance to help you get started with automating your infrastructure the smart way.

Let's get into it.

What is Ansible?

Ansible is a widely used open-source automation tool that makes automation easy for different kinds of operations. IT professionals use it a lot for tasks like putting apps in place, updating systems, setting up cloud services, handling configurations, and organizing services. Basically, it helps with almost anything a sysadmin does regularly. Plus, this tool is easy to set up because it doesn't need extra agent software or security stuff.

Since Ansible is all about automation, you need to give it instructions for each task. Everything's written down in simple scripts, so version control is a breeze. This really helps with the whole infrastructure as code thing in IT. That means treating the upkeep of servers and systems just like you would in software development. You get collections of solutions that are easy to read, tested, and ready to keep things running smoothly, no matter who's on staff.

Even though it is big in automation, sysadmin, and DevOps, regular users can still get a lot out of it. You can set up not just one computer, but a whole bunch at once. And the best part? You don't need to know how to code. The instructions are super easy to read, so anyone can understand them, whether you're a computer newbie or a pro.

Enroll in igmGuru's Red Hat Ansible Course program to become master in automation

How to Install Ansible?

Let's get you started with Ansible by installing it on a control node first. Any device capable of sending or receiving information is called a node in networking. This includes smartphones, desktop computers, tablets, laptops and more devices like these. It will orchestrate various tasks and manage machines from this node.

Installation Requirements

The control node, which is the machine where you run Ansible, needs Python 3.8 or newer. Note that Windows is not a supported operating system for the control node.

For the managed nodes (the servers Ansible will configure), Ansible communicates using SSH and SFTP. If you're managing Windows hosts, it will instead use WinRM. Managed nodes also need either Python 2 (2.6+) or Python 3 (3.5+). Windows nodes require PowerShell 3.0 or newer and .NET 4.0 or later. However, the most common way is considered pip for the installation procedure. This is how you install it -

$ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py

$ python get-pip.py --user

Once pip is installed -

$ python -m pip install --user ansible

Demo Setup

Now that Ansible is installed, let's set up a quick demo. I will use my laptop as the control node. I'll use Vagrant and VirtualBox to make two local Ubuntu virtual machines that will be managed by Ansible.

To follow along, make sure you have Vagrant and VirtualBox installed. The setup files for this demo are in this GitHub repository.

This will fire up two Ubuntu machines in VirtualBox, which we'll then use as our managed hosts for this example. BTW, you can open VirtualBox and check that those two virtual machines are there if you want. Last, to grab the details needed to make our hosts file, run this:

vagrant ssh-config

Installing Ansible Across Different Operating Systems

1. RHEL

With Red Hat Enterprise Linux (RHEL), you get Ansible as part of your subscription. It's already there in the software place, so you know it'll be stable and supported for your business. To get Ansible going on RHEL, just do this:

sudo yum update -y

sudo dnf install -y ansible-core

#Validate Ansible:

ansible ---version

2. MacOS

If you're on a Mac, you can use Homebrew to get this done; just run this command:

brew update

brew install ansible


#Validate Ansible:

ansible ---version

3. Ubuntu

Ubuntu uses APT to install apps. Just run these commands to get Ansible on your Ubuntu OS:

sudo apt update && sudo apt upgrade -y

sudo apt install software-properties-common


sudo add-apt-repository --yes --update ppa:ansible/ansible


#Install Ansible

sudo apt install ansible -y


#Validate Ansible:

ansible ---version

4. CentOS

CentOS also uses YUM, so you can just grab Ansible from the EPEL repo.

sudo yum update -y

sudo yum install epel-release

sudo yum install ansible


#Validate Ansible:

ansible ---version

Read Also: Ansible Interview Questions and Answers

Ansible Tutorial: Core Concepts of Ansible

Let's now discuss some important concepts of Ansible.

1. Ansible-Config

This command is how you check and tweak Ansible's settings. It lets you see all the options and change them - things like the remote user, where modules are stored, and how Ansible the server. This is needed when you're getting Ansible set up just right for what you need it to do.

2. Ansible-Console

This command is used to jump into an interactive session where you can run Ansible tasks and commands. It's like a sandbox for testing and fixing playbooks, which makes creating and debugging automation way simpler. You can run modules, check variables, and get instant feedback - really helpful for DevOps and sysadmins.

3. Ansible-Doc

Need help with a module or plugin? Just type this command followed by the module/plugin name. It pulls up all the info, examples, and options for that specific thing. It's a great way to understand and use Ansible's huge collection of modules for automation and setup.

4. Ansible-Galaxy

This command helps you deal with Ansible roles. You can use it to find, grab, make, and share roles on Ansible Galaxy. Roles are pre-built chunks of automation, so this command lets you add features to Ansible or share what you've built with others. It makes managing roles and working together easier.

5. Ansible-Inventory

This command lets you show your inventory info. That's the list of all the computers and groups Ansible can manage. It lets you see and organize where your inventory comes from, making sure Ansible knows what it's talking to. That way, your automation goes to the right places.

6. Ansible-Playbook

This command is super important. It runs automation tasks from files called playbooks. Playbooks are written in YAML and tell Ansible what you want your systems to look like. Running this command kicks off all the tasks and configurations defined in the playbook, so everything is consistent across your IT stuff. It's a core command for anyone doing DevOps or sysadmin with Ansible.

7. Ansible-Pull

`ansible-pull` is an interesting option and it works differently. Instead of pushing instructions from a central server to other servers, it tells the other servers to ask a central repository for their instructions. This makes it easier to manage configurations on servers without needing a dedicated central server to push to it. It automates config management of remote servers since the configurations are pulled instead of pushed, making it useful for managing infrastructure as code.

8. Ansible-Vault

Got passwords or API keys? Protect them with `ansible-vault`. This command encrypts sensitive stuff inside your playbooks and variable files. That way, only people with the right password or key can access the data when Ansible runs. It keeps your automation workflows secure, which is always a smart move.

Read Also- DevOps Interview Questions and Answers

Ansible Tutorial: Key Terminologies Explained

Let's quickly explain some Ansible terminologies.

i) Playbooks

Think of a playbook as a script for setting up or changing things on your servers. It spells out exactly what you want to happen, like installing software or tweaking settings.

Example - A playbook could install and set up the Apache web server on a bunch of computers. It would handle things like updating the software list, getting Apache, and starting it up.

Why use it? - Imagine setting up a bunch of web servers the same way. A playbook makes sure they're all identical and saves you tons of manual work.

ii) Managed Hosts

These are the servers that Ansible controls. You install Ansible on one computer (your control node), and it uses SSH to talk to and manage these servers.

Example - If you have a bunch of Ubuntu servers, those are your managed hosts. Ansible can connect to them and install updates.

Why use it? - You can automatically keep all your servers secure with the newest patches by running a playbook regularly.

iii) Control Node

This is the computer where Ansible lives and runs. From here, you send commands and playbooks to your other servers.

Example - It could be your laptop or a dedicated server.

Why use it? - One central spot to manage tons of servers, making things like deploying apps and setting up systems way easier.

iv) Task

A task is just one thing that Ansible does. You string tasks together into plays, which then run on your managed hosts.

Example - Installing a package (like Nginx) or restarting a service.

Why use it? - Quickly set up a web server by automating the steps: install Nginx, configure the firewall, and make sure it starts automatically.

v) Machine

Any physical or virtual server that Ansible can manage

Example - Cloud servers (like AWS), physical servers, or even things like network devices.

Why use it? - Ansible can work in mixed environments, so updating everything is simpler.

vi) Modules

These are like little tools that Ansible uses to do things on your servers.

Example - There's a module for managing software packages (apt on Debian/Ubuntu) and one for managing user accounts.

Why use it? - Automate boring tasks, like making users, setting permissions, or deploying code.

vii) Roles

A role is a pre-packaged set of tasks and files for setting up something specific.

Example - A role for setting up a database server (like MySQL) might include installing the software, creating users, and setting up the configuration files.

Why use it? - Make sure all your servers are set up the same way across different environments.

viii) Variables

These are used to store values that you can reuse.

Example - Store the version number of a piece of software.

Why use it? - Change settings for different environments (development, production) without messing with the playbook itself.

Getting a handle on these Ansible terms makes automating your server tasks way simpler.

Read Also- Docker Interview Questions and Answers

Understanding Ansible Inventory

The Ansible Inventory is key to Ansible, the famous automation tool. It's like a master list of all the machines, servers, and devices that Ansible manages in your IT setup.

Think of the Ansible Inventory as a document, usually in INI or YAML format. This document has info on your machines, like their IP addresses, domain names, and other important details like login info and SSH keys.

The inventory file also helps you sort machines into groups based on what they have in common. For example, you can group machines by what they do (like web servers or database servers), where they are in your workflow (dev, staging, live), where they are geographically, or any other system that makes sense for your setup.

By grouping machines, the Ansible Inventory lets you target specific sets of machines when you're automating things or running Ansible playbooks. This grouping feature makes things more efficient, flexible, and easier to understand, letting you apply settings and run tasks across many machines without much effort.

Basic Ansible Commands

Ansible commands are how you automate your infrastructure. With simple commands or playbooks (YAML files that list hosts and tasks), you can set up or take down whole server setups super fast.

Quick Tasks

Here's how to use Ansible commands for everyday stuff:

Task 1: Start/Stop a Service

  • To start or stop a service on another server, try this:

`$ ansible -m service -a "name= state="`

  • To start Apache on `server1`, you'd type:
`$ ansible server1 -m service -a "name=httpd state=started"`

Task 2: Install a Package

  • To install a package, the command is:
`$ ansible -m yum -a "name= state=present"`
  • So, to install the Apache HTTP Server on `server1`, you'd do:
`$ ansible server1 -m yum -a "name=httpd state=present"`

Important Ansible Commands

Ansible commands are strong and automate a lot. Here are some common ones:

  • `ansible-playbook`- The main command to run playbooks. Playbooks are sets of instructions for remote hosts.
  • `ansible-doc`- Checks documentation for Ansible modules. `ansible-galaxy`-Install roles from Galaxy, a community role collection.
  • `ansible-vault`- Encryption or decryption of secret data.
  • `ansible-console`- Starts an interactive Ansible session.
  • `ansible-pull`- Gets playbooks from a Git repo.
  • `ansible-inventory`- Makes an inventory file.

Ansible Variables Explained

Ansible variables let you set values you can reuse in playbooks. Store values for reuse, or use them in conditions and loops. This tool has two variable types: facts and vars. Facts are auto-filled by Ansible with info about the system. Vars are custom variables for strings, numbers, lists, etc.

YAML Basics in Ansible

YAML is a readable way to format data, often for config files. It's easy to learn and works with JSON or XML. Ansible uses YAML because it's readable and easy for computers to parse.

How YAML Tags Work?

YAML tags in Ansible specify the type of data in a variable. It's useful with lists or dictionaries. Tagging data makes sure Ansible interprets it right.

Conclusion Ansible Tutorial

Ansible is designed to be simple. It only needs Python and a couple of libraries on both the main computer and the ones it manages. Most Linux computers already have these. This makes setting it up easy.

No matter what you use - Ubuntu, RHEL, CentOS, MacOS, or Windows - you can put Ansible on it. Windows can't be the main computer because it needs Python and SSH. but there are ways to get around this. You could use Windows Subsystem for Linux (WSL), Docker, or a virtual machine to manage Windows computers.

FAQs For Ansible Tutorial

Q1. Can I install Ansible on Windows?

Yes, ansible supports SSH for windows. However, it's not preferable for production use and is entirely experimental.

Q2. What basic language is utilized by Ansible?

It utilizes declarative markup language YAML.

Q3. Can I learn this tool using the Ansible tutorial?

Yes, using this guide, you can learn Ansible.

Q4. Is Ansible good for beginners?

Yes, Ansible is beginner-friendly because it uses simple YAML syntax and does not require complex coding.

Q5. What is Ansible used for?

Ansible is used to automate IT tasks such as server setup, software installation, configuration management and cloud provisioning.

Course Schedule

Course NameBatch TypeDetails
Red Hat Ansible Training
Every WeekdayView Details
Red Hat Ansible Training
Every WeekendView Details
About the Author
Priyanka Sharma
About the Author

Priyanka is a versatile technical content writer with expertise in Blockchain, Cloud Computing, Software Testing, UI/UX, and Corporate Training. With a strong ability to cover diverse tech domains, she focuses on creating clear, practical, and easy-to-understand content for a wide audience.

Drop Us a Query
Fields marked * are mandatory
×

Your Shopping Cart


Your shopping cart is empty.