0/1 Lessons

Course Introduction

• 19min

0 / 2 lessons complete

IT Lab Setup

• 31min

0 / 3 lessons complete

Installing Ansible

• 57min

0 / 4 lessons complete

Managing your Ansible Inventory

• 2hr 45min

0 / 8 lessons complete

Ansible Basics

• 2hr 54min

0 / 9 lessons complete

Ansible Roles

• 2hr 38min

0 / 8 lessons complete

Ansible Galaxy

• 2hr 28min

0 / 6 lessons complete

Ansible Facts, Variables, Passwords and Templates

• 3hr 20min

0 / 9 lessons complete

Advanced Ansible Playbook Creation

• 2hr 23min

0 / 8 lessons complete

Course Conclusion

• 11min

0 / 1 lessons complete

Playbooks and Plays Overview


Q&A (0)

Notes (0)

Resources (0)

Saving Progress...


There are no resources for this lesson.

Notes can be saved and accessed anywhere in the course. They also double as bookmarks so you can quickly review important lesson material.

Create note

In this lesson, we'll explore the concepts of playbooks and plays in Ansible, which are fundamental to understanding how Ansible automates tasks across multiple systems. By the end of this lesson, you will have a clear understanding of what playbooks and plays are, how they function, and why they are vital in the Ansible ecosystem.

What are Ansible Playbooks?

Ansible playbooks are the core files where Ansible code is written. Written in YAML, playbooks are a series of instructions that tell Ansible what to execute. They are essentially the automation scripts that Ansible uses to configure, deploy, and manage nodes (servers). Each playbook can contain multiple plays.

Structure of a Playbook

A playbook is composed of one or more 'plays'. These plays are sets of tasks that are executed on a particular set of hosts to achieve your desired state on those hosts.

Here is a high-level view of a playbook's structure:

Ansible Playbook, Plays, and Tasks breakdown
Ansible Playbook, Plays, and Tasks breakdown

Understanding Plays

Plays are the heart of a playbook. Each play is designed to target a specific group of hosts and achieve a specific goal on these hosts. For example, a play might be used to install a particular software package on all web servers or to restart services on all database servers.

The power of Ansible comes from its simplicity and flexibility. A single playbook can contain multiple plays, each targeting different sets of hosts with different tasks. This allows for complex orchestration and coordination across different servers and groups within your infrastructure.

Tasks in Plays

Within each play, you define a series of tasks. Tasks are the units of action in Ansible. They are essentially module calls, which are small programs that do the actual work in Ansible, like installing packages, copying files, or creating users.

A task typically includes the name of the module to be used and a list of arguments for that module. Each task is executed sequentially by Ansible on all hosts specified in the play before moving on to the next task.

Idempotency: A Key Concept


One of the critical concepts in Ansible, and particularly in playbooks, is idempotency. This principle ensures that running a playbook multiple times on the same set of hosts does not change the outcome after the first successful run. In other words, Ansible playbooks should be designed in such a way that they can be run repeatedly without causing unexpected side effects.


Understanding playbooks and plays is crucial for anyone looking to leverage Ansible for automation. Playbooks provide the framework for automating a wide range of tasks across your infrastructure, from simple configurations to complex deployments. By grasping the structure and function of playbooks and plays, you are now better equipped to dive into creating and executing your own playbooks in Ansible.

In the next lesson, we'll move from theory to practice as you create and execute your first Ansible playbook. Prepare to apply the concepts you've learned and experience the power of Ansible automation firsthand!

Server Academy Members Only

Sorry, this lesson is only available to Server Academy Full Access members. Become a Full-Access Member now and you’ll get instant access to all of our courses.

0 0 votes
Lesson Rating
Notify of
profile avatar
Inline Feedbacks
View all comments