- AnsibleFest
- Products
- Community
- Webinars & Training
- Blog

Documentation

# Playbooks

Playbooks are Ansible’s configuration, deployment, and orchestration language. They can describe a policy you want your remote systems to enforce, or a set of steps in a general IT process.

If Ansible modules are the tools in your workshop, playbooks are your instruction manuals, and your inventory of hosts are your raw material.

At a basic level, playbooks can be used to manage configurations of and deployments to remote machines. At a more advanced level, they can sequence multi-tier rollouts involving rolling updates, and can delegate actions to other hosts, interacting with monitoring servers and load balancers along the way.

While there’s a lot of information here, there’s no need to learn everything at once. You can start small and pick up more features over time as you need them.

Playbooks are designed to be human-readable and are developed in a basic text language. There are multiple ways to organize playbooks and the files they include, and we’ll offer up some suggestions on that and making the most out of Ansible.

It is recommended to look at Example Playbooks while reading along with the playbook documentation. These illustrate best practices as well as how to put many of the various concepts together.

- Intro to Playbooks
  - About Playbooks
  - Playbook Language Example
  - Basics
  - Action Shorthand
  - Handlers: Running Operations On Change
  - Executing A Playbook
  - Ansible-Pull
  - Tips and Tricks
- Creating Reusable Playbooks
  - Including and Importing
  - Roles
  - Dynamic vs. Static
  - Differences Between Static and Dynamic
  - Tradeoffs and Pitfalls Between Includes and Imports
- Variables
  - What Makes A Valid Variable Name
  - Variables Defined in Inventory
  - Variables Defined in a Playbook
  - Variables defined from included files and roles
  - Using Variables: About Jinja2
  - Jinja2 Filters
  - Hey Wait, A YAML Gotcha
  - Information discovered from systems: Facts
  - Turning Off Facts
  - Local Facts (Facts.d)
  - Ansible version
  - Fact Caching
  - Registered Variables
  - Accessing Complex Variable Data
  - Magic Variables, and How To Access Information About Other Hosts
  - Variable File Separation
  - Passing Variables On The Command Line
  - Variable Precedence: Where Should I Put A Variable?
  - Variable Scopes
  - Variable Examples
  - Advanced Syntax
- Templating (Jinja2)
  - Filters
  - Tests
  - Lookups
  - Examples
  - Python Version and Templating
- Conditionals
  - The When Statement
  - Loops and Conditionals
  - Loading in Custom Facts
  - Applying ‘when’ to roles, imports, and includes
  - Conditional Imports
  - Selecting Files And Templates Based On Variables
  - Register Variables
- Loops
  - Standard Loops
  - Nested Loops
  - Looping over Hashes
  - Looping over Files
  - Looping over Fileglobs
  - Looping over Filetrees
  - Looping over Parallel Sets of Data
  - Looping over Subelements
  - Looping over Integer Sequences
  - Random Choices
  - Do-Until Loops
  - Finding First Matched Files
  - Iterating Over The Results of a Program Execution
  - Looping Over A List With An Index
  - Using ini file with a loop
  - Flattening A List
  - Using register with a loop
  - Looping over the inventory
  - Loop Control
  - Loops and Includes in 2.0
  - Writing Your Own Iterators
- Blocks
  - Error Handling
- Strategies
  - Strategy Plugins
- Best Practices
  - Content Organization
  - Staging vs Production
  - Rolling Updates
  - Always Mention The State
  - Group By Roles
  - Operating System and Distribution Variance
  - Bundling Ansible Modules With Playbooks
  - Whitespace and Comments
  - Always Name Tasks
  - Keep It Simple
  - Version Control
  - Variables and Vaults