Ansible: Playbooks Deep Dive

Course

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.

Length

06:59:40

Difficulty

Intermediate

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: https://interactive.linuxacademy.com/diagrams/AnsiblePlaybooks.html

Syllabus

Introduction

Course Overview

About the Course

00:02:04

Lesson Description:

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

About the Training Architect

00:00:35

Lesson Description:

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

Course Features and Tools

00:03:17

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

00:03:00

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

00:07:46

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 https://linuxacademy.com/cp/courses/lesson/course/3928/lesson/2/module/317 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.

Ansible Playbooks

Playbook Basics

Using YAML for Ansible Playbooks

00:07:33

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

00:07:37

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

00:06:48

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

00:04:46

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.

01:00:00

Essential Playbook Syntax

Using Variables in Playbooks

00:17:43

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

00:06:08

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

00:10:59

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

00:08:13

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

00:04:57

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

00:07:17

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.

01:30:00

Advanced Playbook Syntax

Executing Selective Parts of a Playbook

00:05:55

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

00:14:05

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

00:09:41

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

00:06:58

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

00:05:36

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`

00:05:11

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

00:07:48

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:https://linuxacademy.com/cp/courses/lesson/course/3933/lesson/2/module/317

Using `run_once`

00:03:14

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

00:07:24

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

00:12:51

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 https://docs.ansible.com/ansible/latest/user_guide/playbooks_reuse.html 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.

01:30:00

Conclusion

Course Wrap Up

Conclusion and Next Steps

00:02:04

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.