Write a playbook

Create a playbook that pings your hosts and prints a "Hello world" message.

About this task

Ansible uses the YAML syntax. YAML is a human-readable language that enables you to create playbooks without having to learn a complicated coding language.

Procedure

  1. Create a file named playbook.yaml in your ansible_quickstart directory, 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
  2. Run your playbook:
    $ ansible-playbook -i inventory.ini playbook.yaml

Results

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