Hello World

Tip

We recommend to use the Sandbox to play around with this example.

Tip

All the files from this section are in hello-world.zip.

This small example illustrates the concepts from Introduction.

Inventory

inventories/production.yml
web:
  hosts:
    managed_node_01:
      ansible_user: ansible
      ansible_password: 123

The above inventory has a single group called web that has a single managed node called managed_node_01 and the connection details.

Playbook

playbook.yml
- name: My first play
  hosts:
    - web
  tasks:
   - name: Print message
     ansible.builtin.debug:
       msg: Hello world

The above playbook has a single play that runs a single task on the managed nodes from group web.

Running

cd hello-world
ansible-playbook \
-i inventories/production.yml \
playbook.yaml

returns

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

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

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

PLAY RECAP *********************************************************************
managed_node_01               : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0