AnsiblePilot — Master Ansible Automation
AnsiblePilot is the leading resource for learning Ansible automation, DevOps, and infrastructure as code. Browse over 1,400 tutorials covering Ansible modules, playbooks, roles, collections, and real-world examples. Whether you are a beginner or an experienced engineer, our step-by-step guides help you automate Linux, Windows, cloud, containers, and network infrastructure.
Popular Topics
About Luca Berton
Luca Berton is an Ansible automation expert, author of 8 Ansible books published by Apress and Leanpub including "Ansible for VMware by Examples" and "Ansible for Kubernetes by Example", and creator of the Ansible Pilot YouTube channel. He shares practical automation knowledge through tutorials, books, and video courses to help IT professionals and DevOps engineers master infrastructure automation.
Ansible terminology - What is an Ansible Playbook? — Video Tutorial
A step-by-step guide inside the Ansible Playbook anatomy: play, tasks, modules, conditional, loop, handler, variable, list.
What You'll Learn
- What is an Ansible Playbook?
- Ansible Playbook
- Links
- Playbook
- code
- execution
- Conclusion
- Related Articles
Full Tutorial Content
What is an Ansible Playbook?
I will show you a live Playbook with some simple Ansible code.
I'm Luca Berton, and welcome to today's episode of Ansible Pilot.
Ansible Playbook
- blueprint for automation
- YAML format
- Ansible language
The Ansible Playbook is the blueprint for your automation. The Ansible Playbook enables you to execute any, again again, operation in a specified order.
It's like a recipe book for someone who likes to cook a cake. Every ingredient needs to be added in a specific order at a particular moment of the execution.
The code is human-readable in YAML format, a well-known easy-to-read coding format. Every line of coding is the Ansible language that is changed a little bit yearly, but the principles are always the same.
Like all programming languages, you can declare variables, include other files, execute actions on conditions, and repeat with loops.
Other particular actions, called handlers, execute only when another task is performed.
You can execute your Ansible Playbook using the `ansible-playbook` command line utility included in any ansible installation.
When the execution is successful, you obtain a green result, otherwise a failure with a relative error.
Links
- https://docs.ansible.com/ansible/latest/user_guide/playbooks_intro.html
Playbook
A step-by-step guide inside the Ansible Playbook anatomy.
code
- example.yml
```yaml
---
- name: example playbook
hosts: all
vars:
myvar: "example text"
mybool: true
cities:
- New York
- Paris
tasks:
- name: print var
ansible.builtin.debug:
var: myvar
notify: reload
- name: condition
ansible.builtin.debug:
msg: "example condition"
when: mybool
- name: print cities
ansible.builtin.debug:
var: item
loop: "{{ cities }}"
handlers:
- name: reload
ansible.builtin.debug:
msg: "example handler"
```
execution
```bash
$ ansible-playbook -i ../vmware/inventory example.yml
PLAY [example playbook] *****************************************************************
TASK [Gathering Facts] ******************************************************************
[WARNING]: Platform darwin on host localhost is using the discovered Python interpreter
at /opt/homebrew/bin/python3.10, but future installation of another Python interpreter
could change the meaning of that path. See https://docs.ansible.com/ansible-
core/2.13/reference_appendices/interpreter_discovery.html for more information.
ok: [localhost]
TASK [print var] ************************************************************************
ok: [localhost] => {
"myvar": "example text"
}
TASK [condition] ************************************************************************
ok: [localhost] => {
"msg": "example condition"
}
TASK [print cities] *********************************************************************
ok: [localhost] => (item=New York) => {
"ansible_loop_var": "item",
"item": "New York"
}
ok:
About This Tutorial
- Author: Luca Berton
- Difficulty: Beginner
- Read time: 3 min
- Category: installation
Read the full written article: Ansible terminology - What is an Ansible Playbook?