A simple launch task if the role is included in the playbook

Imagine a player with the following roles: base, monitoring, nginx and another play with base and nginx.

Now I want the monitoring role to perform the task only if the nginx role is included in the playbook, because for monitoring nginx I need to transfer a slightly different configuration to the monitoring service.

How to perform a task that depends on the existence of a different role?

+6
source share
1 answer

Although my workaround in the comments may have worked for you, I believe this is not a good approach. It is not modular. For example, in a situation where you are changing the monitoring system, you need to enter each role and check if it has a monitoring component and update it ... Not the best way.

Perhaps the best way is to still include a separate monitoring role, but specific tasks are performed there using book conventions . For example, the nginx monitoring task will only be performed when , this server is part of your group [webservers]. Or when a particular variable is set to a specific value or some other appropriate condition is met.

+2
source

All Articles