Ansible terminology - What is an Ansible Playbook?
By Luca Berton · Published 2024-01-01 · Category: installation
A step-by-step guide inside the Ansible Playbook anatomy: play, tasks, modules, conditional, loop, handler, variable, list.

What is an Ansible Playbook?
I will show you a live Playbook with some simple Ansible code.See also: Ansible selectattr & map Filters: Filter Data from Lists (Complete Guide)
Ansible Playbook
- blueprint for automation
- YAML format
- Ansible language
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
See also: Ansible Vault: Encrypt, Decrypt & Manage Secrets (Complete Guide)
Playbook
A step-by-step guide inside the Ansible Playbook anatomy.code
- example.yml
---
- 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
$ 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: [localhost] => (item=Paris) => {
"ansible_loop_var": "item",
"item": "Paris"
}
PLAY RECAP ******************************************************************************
localhost : ok=4 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0Conclusion
Now you know what an Ansible Playbook is and how to use it. You know how to use it based on your use case.
See also: Use Ansible Vault in Ansbile Playbook - ansible vault
Related Articles
Category: installation
Watch the video: Ansible terminology - What is an Ansible Playbook? — Video Tutorial