Example 5
hosts.yml
centos:
hosts:
provisioner:
ansible_connection: local
centos1:
ansible_host: '192.168.77.22'
ubuntu:
hosts:
ubuntu1:
ansible_host: '192.168.77.23'
playbook.yml
- name: Example playbook
hosts: all
gather_facts: false
tasks:
- name: Example task
command: whoami
notify: whoami_handler
handlers:
- name: whoami_handler
debug:
msg: "Whoami was called on {{ inventory_hostname }}"
Tip
Handlers
are special tasks, which are always run at the end of a playbook. They are called by the notify
directive. They are often used to perform post-installation modifications eg. starting of services, editing configuration files.
Execute the following command
ansible-playbook playbook.yml