Jump to section

What is an Ansible Playbook?

Copy URL

An Ansible® Playbook is a blueprint of automation tasks, which are IT actions executed with limited manual effort across an inventory of IT solutions. Playbooks tell Ansible what to do to which devices.

Instead of manually applying the same action to hundreds or thousands of similar technologies across IT environments, executing a playbook automatically completes the same action for the specified type of inventory—such as a set of routers. Playbooks also serve as frameworks of prewritten code that developers can use ad-hoc or as a starting template.

Playbooks are regularly used to automate IT infrastructure—such as operating systems and Kubernetes platforms—networks, security systems, and code repositories like GitHub. IT staff can use playbooks to program applications, services, server nodes, and other devices, without the manual overhead of creating everything from scratch.

And playbooks—as well as the conditions, variables, and tasks within them—can be saved, shared, or reused indefinitely. This makes it easier for IT teams to codify operational knowledge and ensure that the same actions are performed consistently.

Ansible Playbooks are lists of tasks that automatically execute for your specified inventory or groups of hosts. One or more Ansible tasks can be combined to make a play—an ordered grouping of tasks mapped to specific hosts—and tasks are executed in the order in which they are written. A playbook can include 1 or more plays as well as Ansible Roles—bundles of tasks and associated automation assets that can be run in multiple plays or reused across playbooks.

Tasks are executed by modules, each of which performs a specific task in a playbook. A module contains metadata that determines when and where a task is executed, as well as which user executes it. There are thousands of Ansible modules that perform all kinds of IT tasks, such as:

Cloud management

oci_vcn creates, deletes, or updates virtual cloud networks in Oracle Cloud Infrastructure environments. Similarly, vmware_cluster adds, removes, or updates VMware vSphere clusters.

User management

selogin maps Linux® operating system (OS) users to SELinux user, and gitlab_user creates, updates, or deletes GitLab users.

Networking

Dozens of modules handle application programming interfaces (APIs); Cisco IOS, NXOS, and IOS XR devices; as well as F5 BIG-IP services and the Arista EOS cloud network operating system.

Security

Openssh_cert generates an OpenSSH host or user certificates, and ipa_config manages global FreeIPA configuration settings.

Configuration management

pip manages Python library dependencies while assemble consolidates configuration files from fragments.

Communication

mail can automatically send emails based on certain criteria, and snow_record creates, deletes, or updates a single record in ServiceNow.

Ansible is capable of communicating with many different device classifications, from cloud-based REST APIs, to Linux and Windows systems, networking hardware, and much more. This is a sample of 2 Ansible modules automatically updating 2 types of servers:

---
- name: Update web servers
  hosts: webservers
  become: true
 
  tasks:
    - name: Ensure apache is at the latest version
      ansible.builtin.yum:
        name: httpd
        state: latest
    - name: Write the apache config file
      ansible.builtin.template:
        src: /srv/httpd.j2
        dest: /etc/httpd.conf
        mode: "0644"
 
- name: Update db servers
  hosts: databases
  become: true
 
  tasks:
    - name: Ensure postgresql is at the latest version
      ansible.builtin.yum:
        name: postgresql
        state: latest
    - name: Ensure that postgresql is started
      ansible.builtin.service:
        name: postgresql
        state: started

The playbook contains 2 plays: 

  • The first checks whether or not web server software is up to date and runs the update if necessary.
  • The second checks whether or not database server software is up to date and runs the update if necessary.

Ansible uses the YAML syntax. Depending on whom you ask, YAML stands for yet another markup language or YAML ain’t markup language (a recursive acronym). There are also 2 different, but perfectly acceptable YAML file extensions: .yaml or .yml. 

There are 2 ways of using Ansible Playbooks: from the command line interface (CLI) or using the Red Hat® Ansible Automation Platform’s push-button deployments.

Because YAML is a human-readable language, IT professionals with specific domain expertise—like in network, security, or cloud—can create playbooks without having to learn a complicated coding language.

From the CLI

After installing the open source Ansible project or Red Hat Ansible Automation Platform—which is as straightforward as typing `sudo yum install ansible` in the Red Hat Enterprise Linux CLI—all you need to do is use the ansible-playbook command to run Ansible Playbooks.

From within the platform

The Red Hat Ansible Automation Platform web-based user interface includes push-button Ansible Playbook deployments that are used as part of larger jobs or job templates. These deployments come with additional safeguards that are particularly helpful to users who are newer to IT automation—or those without as much experience working in the CLI.

There’s a lot more to do with automation.

Red Hat Ansible Automation Platform is a unified platform that can automate full processes across your IT domains for a variety of use cases—including infrastructure, hybrid cloud, security, and networks, all the way to edge locations. Ansible Automation Platform includes all the tools needed to implement enterprise-wide automation, including an event-driven solution, playbooks, and analytics. And it allows your teams to centralize and control your IT infrastructure with a visual dashboard, role-based access control, and other features that will help reduce operational complexity.

With a Red Hat subscription, you get certified, supported content from Red Hat and our partners, access to hosted management services, and life cycle technical support to scale automation across your organization. And you’ll get expert knowledge gained from our success with thousands of customers.

The introduction of Red Hat Ansible Lightspeed with IBM watsonx Code Assistant makes Ansible even more accessible to beginners and helps experienced automation teams learn, create, and maintain Ansible Automation Platform content more efficiently. This generative AI service accepts prompts entered by a user and then interacts with IBM watsonx foundation models to produce code recommendations built on Ansible best practices—helping you convert subject matter expertise into trusted, reliable Ansible code that scales across teams and domains.

Icon-Red_Hat-Media_and_documents-Quotemark_Open-B-Red-RGB The built-in capabilities of Red Hat Ansible Automation Platform provide an accelerator in a box. It’s the de facto standard that many of our vendors and partners also use to write scripts to install, configure, and maintain their technology.

Jesse Amerson

IT director, Ulta Beauty

How much time could automation save you?

Answer a few short questions to find out how much time you could save by using Ansible Automation Platform across your organization.

Keep reading

Article

Learning Ansible basics

Ansible automates IT processes like provisioning and configuration management. Learn the basics of Ansible with this introduction to key concepts.

Article

What's an Ansible Playbook?

An Ansible Playbook is a blueprint of automation tasks, which are IT actions executed with limited manual effort across an inventory of IT solutions.

Article

Why choose Red Hat for automation?

Red Hat Ansible Automation Platform includes all the tools needed to share automation across teams and implement enterprise-wide automation.

More about automation

Products

A unified solution that combines the security, features, integrations, and flexibility needed to scale automation across domains, orchestrate essential workflows, and optimize IT operations for AI adoption. 

Engagements with our strategic advisers who take a big-picture view of your organization, analyze your challenges, and help you overcome them with comprehensive, cost-effective solutions.

Resources

E-BOOK

Red Hat Ansible Automation Platform: A beginner’s guide

Customer Success Stories

See how our customers have used Ansible Automation Platform to accelerate IT operations

Podcast

Code Comments Season 2: Hear how organizations have adapted to do more with IT automation 

Training

Learning hub

Explore learning materials and tools designed to help you use Ansible Automation Platform, organized by the tasks you need to accomplish. 

Interactive Labs

These interactive scenarios let you start learning how to use Ansible Automation Platform for a variety of use cases—in your own browser. 

Technical Overview

This series of on-demand videos introduces you to using Ansible Automation Platform for a variety of use cases across IT environments.

Automating RED HAT ENTERPRISE LINUX

This course will teach you how to automate Linux® system administration tasks with the latest version of Ansible Automation Platform.