From the course: Red Hat Certified Engineer (EX294) Cert Prep: 2 Using Ansible Playbooks

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Playbook change handlers

Playbook change handlers

From the course: Red Hat Certified Engineer (EX294) Cert Prep: 2 Using Ansible Playbooks

Start my 1-month free trial

Playbook change handlers

- [Instructor] As I've mentioned before, modules should be idempotent, so you can run a playbook as many times as you want, and the results are always the same. If a task is already in the desired state, that task should exit. If a task makes a change, we can fire an event using Ansible's basic event system that can be used to respond to that change. Let me first talk about how we'd do this without using Ansible's event system and outline the pitfalls. Let's say we create a task using the copy module, in this task we copy the apache config file to its appropriate destination on our node. After this, we use a service module to restart the service. We could make an additional task that ensures that the apache package is updated and restart the service as well. The problem is that we're blindly restarting the service, and we may even have more than one task restarted in the apache service unnecessarily. To set up a change…

Contents