Skip to main content

Ansible: Playbooks Deep Dive


Intro Video

Photo of Stosh Oldham

Stosh Oldham

Course Development Director in Content

I have been working with technology in some way or another ever since my high school days. After attaining my bachelor’s degree in computer science, I spent over a decade in IT working on anything from fixing printers to engineering enterprise IT systems. I now have the privilege of sharing my expertise as a Linux Training Architect for Linux Academy. When I am not sitting behind a terminal, I like going on holiday and spending time with my family.







Hands-on Labs


Course Details

This course is the second in a series on Ansible where we focus in on writing Ansible playbooks.

While the first course in the series focused on installation, configuration, and ad-hoc commands, this course discusses what a play and playbook are in Ansible. Many key features of Ansible Playbooks are highlighted as we work through the course and a few new modules are introduced along the way.

Naturally, there are many demonstrations provided and some discussion on potential uses cases for the various features that are covered. Hands-on labs are provided throughout the course for students to practice their knowledge. After completing this course, students should be capable of writing Ansible playbooks for a number of various scenarios!

Interactive Diagram:


Course Overview

About the Course


Lesson Description:

This lesson provides an overview of the topics covered in the Ansible: Playbooks Deep Dive course.

About the Training Architect


Lesson Description:

Get to know your Training Architect for the Ansible: Playbooks Deep Dive course.

Course Features and Tools


Lesson Description:

This lesson goes over some of the tools made availalbe to students as they work through the course content. Be sure to watch so you know how to make the most of your subscription!

About Ansible Playbooks


Lesson Description:

We look at a simple Ansible playbook to get an idea of what exactly an Ansible playbook is and what it does. A brief discussion of plays and playbooks is also provided as compared to Ansible ad-hoc commands.

Advanced Inventory Configuration


Lesson Description:

Note: The inventory referenced in this lesson (as well as future lessons in this course) was created in the "Ansible Configure, Setup, and Ad Hoc Commands Deep Dive" course. See for additional information. This lesson talks about some more advanced options when it comes to an Ansible inventory. Dynamic inventories are covered as well as how they differ from static inventories. A brief introduction to inventory variables is provided with elaboration on variables in a coming lesson.

Playbook Basics

Using YAML for Ansible Playbooks


Lesson Description:

YAML is the language used to craft Ansible playbooks. In this lesson, we go over some of the more commonly used YAML components in Ansible as well as some of the common hang-ups you may run into while working with YAML in an Ansible playbook.

Creating an Ansible Play


Lesson Description:

This lesson provides a broad overview of an Ansible play. A very simple play is constructed and each component is briefly discussed. Playbook formatting is demonstrated and the difference between a play and playbook is also covered.

The `ansible-playbook` Command


Lesson Description:

The ansible-playbook command is used to execute playbooks in Ansible. This lesson talks about a few common options used with the command, as well as its general behavior.

Understanding Playbook Tasks


Lesson Description:

The task is the base unit of work in an Ansible playbook. Essential task formatting and properties are demonstrated in this lesson. Best practices regarding general playbook writing are also discussed.

Hands-on Labs are real live environments that put you in a real scenario to practice what you have learned without any other extra charge or account to manage.


Essential Playbook Syntax

Using Variables in Playbooks


Lesson Description:

This video lesson demonstrates how to define and use variables in Ansible in a broad sense. Variables allow for enhanced automation via loops and runtime status checks. Variables also allow for creating configuration file templates, among other useful features. More information will be provided on variables as the course progresses.

Working with Templates


Lesson Description:

Ansible templates provide a simple means of maintaining various configuration files that may be customized on deployment. This lesson demonstrates how to use the template module in Ansible to deploy a Jinja template file. In addition, the template file format is discussed.

Using Ansible Facts


Lesson Description:

Ansible facts are a great way to collect system properties at runtime! This lesson shows how Ansible facts may be used in playbooks to use runtime system properties in host configuration. There is also a discussion on how Ansible may be configured to cache facts.

Conditional Execution in Playbooks


Lesson Description:

Decision making is a key part of any automation solution. Ansible allows for decision making with the when keyword. Besides introducing the stat module, this lesson demonstrates how conditionals may be used in Ansible for conditional task execution.

Using Loops in Ansible


Lesson Description:

System configuration frequently requires repeating various tasks using different parameters. Ansible helps us tackle this use-case with a built-in loop feature. Watch this lesson to see how to leverage loops in Ansible!

Working with Handlers in Ansible


Lesson Description:

Ansible handlers allow for execution of tasks that are contingent on another tasks making changes. This lesson describes how you can configure and utilize Ansible handlers in your own playbooks!

Hands-on Labs are real live environments that put you in a real scenario to practice what you have learned without any other extra charge or account to manage.


Advanced Playbook Syntax

Executing Selective Parts of a Playbook


Lesson Description:

This lesson talks about Ansible Tags. Tags may be used in Ansible to execute selective parts of a given playbook. Tags are a handy way to target specific, related tasks of a single playbook.

Working with Sensitive Data Using Ansible Vault


Lesson Description:

A common need in configuration management is secure storage for sensitive information, such as passwords. Ansible provides a means for us to protect such data using the ansible-vault command. Ansible vaults are encrypted files which the ansible-playbook command can be configured to unencrypt at playbook runtime. We discuss how to use these features of Ansible within this lesson!

Error Handling in a Playbook - limit, ignore_errors, changed_when, and failed_when


Lesson Description:

Ansible has a number of features for dealing with errors and even defining what an error is! This lesson talks about keywords that can be used to define change conditions, failure conditions, and weather or not errors should be ignored.

Error Handling in a Playbook - Block Groups and The Debug Module


Lesson Description:

Ansible block groups may be used within Ansible playbooks to attempt certain tasks and provide conditional steps based on the attempted task. Ansible also provides a core debug module that allows for printing debug information to stdout during play execution. These two features are essential for general error handling in Ansible and are discussed in this lesson.

Asynchronous Tasks within a Playbook


Lesson Description:

By default, Ansible waits for each task to complete on a target node before continuing on to the next task. There are occasions where that behavior is not ideal. The async and poll keywords allow us to configure Ansible to "fire and forget" a task that may be long running. The keywords also allow us to get around SSH timeout settings when necessary. These features are demonstrated in this lesson.

Delegating Playbook Execution with `delegate_to` and `local_action`


Lesson Description:

Ansible allows for the execution of tasks exclusively on specific hosts as needed. The delegate_to keyword takes a host which a task will be ran against. The delegation of a task with localhost may be delegated to using the shorthand local_action. Both approaches to this are discussed in this lesson.

Parallelism in Playbooks


Lesson Description:

After a brief review of Ansible forks, this lesson talks about the serial and max_fail_percentage keywords. The serial keyword allows for batching of hosts for execution instead of targeting all hosts simultaneously. The max_fail_percentage keyword can configure a play to abort if too many target hosts fail play execution. For a refresher on basic parallelism in Ansible, check out this lesson:

Using `run_once`


Lesson Description:

The run_once keyword allows us to mark a task for only a single execution in a play, no matter how many hosts are targeted. This has select use cases, such as running a script that may only need to be ran one time for a cluster. The keyword is demonstrated in this lesson and a brief discussion is provided as to how run_once interacts with delegate_to and serial.

Overview of Ansible Roles


Lesson Description:

Ansible roles allow for enhanced organization of more complex Ansible playbooks. They also are easily shareable via Ansible Galaxy. This lesson provides a broad overview of the Ansible role structure and a brief look at the ansible-galaxy command.

Ansible Role Demo


Lesson Description:

This lesson goes over creating a very simple role using several of the role directories. The syntax for engaging a role is also discussed, as well as the difference between static and dynamic includes in Ansible. See for more detail on the impact of static vs. dynamic includes.

Hands-on Labs are real live environments that put you in a real scenario to practice what you have learned without any other extra charge or account to manage.


Course Wrap Up

Conclusion and Next Steps


Lesson Description:

Thanks for seeing the course through! In this video, we look at some other topics that may interest students who have completed this course.

Take this course and learn a new skill today.

Transform your learning with our all access plan.

Start 7-Day Free Trial