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.
source share