Skip to main content

Ansible: A beginner's guide to IT automation

Automation lets you work smarter, not harder. Learn Ansible basics so you're ready to start bringing automation into your workflows.

Image by Pexels

It’s always better to work smarter and not harder. Imagine that every time you need to receive some important data, you have to repeat certain tasks. You have to follow the same steps over and over and over. Each set of steps takes an hour to complete. Now multiply that set times 10. Who has that kind of time?

Automating processes is my favorite way to solve this kind of problem. And my favorite tool for automation is Ansible, not just because of its excellent reputation. I use Ansible because it's come to my rescue time and time again.

What is Ansible?

Ansible can change the way you manage infrastructure.

It is considered a DevOps tool because it can help you manage system configuration, development, provisioning, and more by using secure shell (SSH) to communicate between systems.

It utilizes playbooks, written in the simple language YAML, to translate what you define as true in your infrastructure into actions your systems must take to meet that definition.

[ Keep your favorite commands close at hand. Download the advanced Linux commands cheat sheet. ]

Why use Ansible?

It’s essential to provide reliability, scalability, and consistency within your infrastructure. Ansible supports all of these crucial areas and ensures that the required packages and programs are installed and configured correctly.

It also gives you access to previous versions and other historical data. Any time you want to roll back or upgrade, you can do so seamlessly.

Here are some of Ansible's essential features:

  • Agentless: There isn't a central node managing Ansible.
  • Python: Ansible is written in the popular coding language Python, so even intermediate coders can write modules for it. Don't worry if Python isn't your language of choice. You can write modules in other languages, too.
  • Push architecture: Ansible allows you to push configurations (defined in YAML playbooks) to all client nodes at once. This shows how powerful this tool can be. Imagine pushing to thousands of servers at once, with minimal setup time!

Now that I've covered what Ansible is, I'll cover the basics of how it works.

[ Want to test your sysadmin skills? Take a skills assessment today. ]

Ansible architecture

It all starts with the playbook.

Through the Ansible automation engine, you can push actions defined in a playbook over to any number of client hosts. The host inventory file defines which computers on your network are clients.

Here's a simple playbook that ensures a set of target hosts (all clients in the group webhosts, which would be defined in the host inventory file) have the latest httpd installed and configured to run:

- name: Web servers
  hosts: webhosts
    - name: Install httpd package
        name: httpd
        state: latest
    - name: Start and enable httpd service
        name: httpd
        enabled: true
        state: started

Ansible modules are what make such a simple playbook as this example possible. Modules are scripted programs that are executed when running a playbook. There are hundreds of modules bundled with Ansible, and even more are available from its community of users.

A playbook consists of plays, or tasks that call modules. When you run a playbook, you’re calling on the modules referenced in your YAML to complete requests on the host machines.

Plugins are executed before modules. There are many different types of plugins: cache plugins, callback plugins, action plugins, and more. For example, Ansible uses a connection plugin to ensure it can connect to hosts. It usually uses SSH, but you can use a Docker plugin to enable Ansible to connect to and manage containers instead.

[ Need more on Ansible? Take a no-cost technical overview course from Red Hat. Ansible essentials: Simplicity in automation technical overview. ]

Ansible at work

Ansible works by connecting to nodes and executing scripted programs as Ansible modules. By default, Ansible executes modules over SSH. The computer you're using to run the playbook is called the Ansible management node, and it controls the entire playbook. It makes the connection, executes the modules on the target hosts, and performs whatever actions are required by the playbook.

Automation helps tremendously in nearly any organization. It ensures easy access to all the computers on your network and gives you peace of mind knowing that your systems will retain their integrity over time. And this happens without creating memory-hungry daemons running in the background. There are plenty of options and plenty of reasons to use specific systems. With Ansible, there is endless opportunity.

Here are some articles to help you learn Ansible:

Topics:   Ansible   Automation  
Author’s photo

Gabrielle Stenzel

I currently work as a Cloud Support Supervisor for Acronis . I have worked with Linux and OpenSource tools for a decade, constantly wanting to make new resolutions for obstacles and always training others on improving systems as a systems administrator. More about me

Try Red Hat Enterprise Linux

Download it at no charge from the Red Hat Developer program.