Playbooks are automation blueprints, in YAML format, that Ansible uses to deploy and configure managed nodes.
A list of plays that define the order in which Ansible performs operations, from top to bottom, to achieve an overall goal.
An ordered list of tasks that maps to managed nodes in an inventory.
A reference to a single module that defines the operations that Ansible performs.
A unit of code or binary that Ansible runs on managed nodes. Ansible modules are grouped in collections with a Fully Qualified Collection Name (FQCN) for each module.
Complete the following steps to create a playbook that pings your hosts and prints a “Hello world” message:
Create a file named playbook.yaml in your ansible_quickstart directory, that you created earlier, with the following content:
- name: My first play
hosts: myhosts
tasks:
- name: Ping my hosts
ansible.builtin.ping:
- name: Print message
ansible.builtin.debug:
msg: Hello world
Run your playbook.
ansible-playbook -i inventory.ini playbook.yaml
Ansible returns the following output:
PLAY [My first play] ****************************************************************************
TASK [Gathering Facts] **************************************************************************
ok: [192.0.2.50]
ok: [192.0.2.51]
ok: [192.0.2.52]
TASK [Ping my hosts] ****************************************************************************
ok: [192.0.2.50]
ok: [192.0.2.51]
ok: [192.0.2.52]
TASK [Print message] ****************************************************************************
ok: [192.0.2.50] => {
"msg": "Hello world"
}
ok: [192.0.2.51] => {
"msg": "Hello world"
}
ok: [192.0.2.52] => {
"msg": "Hello world"
}
PLAY RECAP **************************************************************************************
192.0.2.50: ok=3 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
192.0.2.51: ok=3 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
192.0.2.52: ok=3 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
In this output you can see:
ok which means it ran successfully.ok=3 indicates that each task ran successfully.Congratulations, you have started using Ansible!
See also
Start building playbooks for real world scenarios.
Go into more detail with Ansible playbooks.
Get tips and tricks for using playbooks.
Learn more about the gather_facts keyword in playbooks.
© 2012–2018 Michael DeHaan
© 2018–2025 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
https://docs.ansible.com/ansible/latest/getting_started/get_started_playbook.html