From the course: Ansible: From Basics to Guru by Pearson

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

Conditionals overview

Conditionals overview

In this video, I will give you an overview of the conditionals. First conditional is loop. Loop is used to process through a list of items, so that you can write one task that goes over each item in the loop. You know, some modules work with a list as an argument, like the yum module. You can provide a list of packages. Some modules don't, like service. How are you going to write a playbook that is efficiently going to restart multiple services? Well, that is where Loop comes in, as you will see. Now we have the handlers. Handlers are used to run specific tasks only if another task has changed something. And that is used when you want to avoid unnecessary reboots and service restarts. You know, after some activity, you need to restart your service or even reboot your server. But you only want to do that if something has changed. And if the playbook hasn't changed anything because the current state already was in accordance with the desired state, you shouldn't reboot. That's where the…

Contents