← Your First Playbook
Write a one-task play
Learn
Plays, tasks and modules
A playbook is a YAML file, a recipe. Its structure is always three nested ideas:
- hosts: localhost # a PLAY: "on these machines…"
gather_facts: false
tasks: # …run these TASKS, in order
- name: Show the date # a human-readable label
ansible.builtin.command: date # the MODULE that does the work
- A play maps a set of hosts to a list of tasks (
hosts: localhost= this machine). - A task is one unit of work, with a
name:for readability. - A module is the tool the task invokes:
debugprints a message,copywrites a file,templaterenders one. A module is the verb; the task is the sentence.
When it runs, Ansible reports each task per host (ok, changed or failed) and ends with
a PLAY RECAP tallying them: localhost : ok=1 changed=0 failed=0 …. Watch those
numbers; they're the heartbeat of every run.
Your task
The starter has an empty play. Add a single task under tasks: that uses the
ansible.builtin.debug module to print the message Ansible is running, then press
Run. You'll see the task report ok: [localhost] and the PLAY RECAP tally it.
- name: Say hello
ansible.builtin.debug:
msg: "Ansible is running"