making service restart Idempotent in Ansible

Now lets talk about how service module can be used in any playbook, so for this i am taking an example of httpd webserver

Using Conditions (when keyword): we can use conditional statements for example, this task will run when given condition satisfies otherwise this task will skip.

using Handlers : handlers are more efficient and better choice to make the service module idempotent rather than using when keyword because handlers are meant for this kind of use-cases

now lets run this playbook and see what happens:

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store