Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ansible, run task if playbook includes role

Let's imagine a playbook with following roles: base, monitoring, nginx and another playbook with only base and nginx.

Now I want in monitoring role to run a task only if playbook includes nginx role, because for monitoring nginx I have to pass a little bit different configuration to monitoring service.

How to execute a task what dependes on another role existence?

like image 945
nvartolomei Avatar asked Jan 17 '14 11:01

nvartolomei


1 Answers

While my workaround in the comments might have worked for you, I feel it's still not the best approach. It's not modular. For example in a situation where you change monitoring system, you'd need to go into each role and check if it has monitoring component and update that...Not the most optimal way.

Perhaps a better way would be to still include a separate monitoring role, but there execute specific tasks using playbook conditionals. For example, nginx monitoring task would execute only when this server is part of your [webservers] group. Or when a certain variable is set to a specific value or some other appropriate conditional is met.

like image 63
Mxx Avatar answered Oct 06 '22 12:10

Mxx