Creating a playbook

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:

  1. 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
       - name: Ping my hosts
       - name: Print message
          msg: Hello world
  2. Run your playbook.

    ansible-playbook -i inventory.ini playbook.yaml

Ansible returns the following output:

PLAY [My first play] ****************************************************************************

TASK [Gathering Facts] **************************************************************************
ok: []
ok: []
ok: []

TASK [Ping my hosts] ****************************************************************************
ok: []
ok: []
ok: []

TASK [Print message] ****************************************************************************
ok: [] => {
    "msg": "Hello world"
ok: [] => {
    "msg": "Hello world"
ok: [] => {
    "msg": "Hello world"

PLAY RECAP ************************************************************************************** ok=3    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0 ok=3    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0 ok=3    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

In this output you can see:

  • The names that you give the play and each task. You should always use descriptive names that make it easy to verify and troubleshoot playbooks.

  • The “Gathering Facts” task runs implicitly. By default, Ansible gathers information about your inventory that it can use in the playbook.

  • The status of each task. Each task has a status of ok which means it ran successfully.

  • The play recap that summarizes results of all tasks in the playbook per host. In this example, there are three tasks so ok=3 indicates that each task ran successfully.

Congratulations, you have started using Ansible!

See also

Ansible playbooks

Start building playbooks for real world scenarios.

Working with playbooks

Go into more detail with Ansible playbooks.

Ansible tips and tricks

Get tips and tricks for using playbooks.

Discovering variables: facts and magic variables

Learn more about the gather_facts keyword in playbooks.