It's not clear to me why this is not working. I can't see a problem. But let me give you some general recommendations, maybe that'll help you too.
Best practice is to have your playbooks on the root level. Have a look at this structure. With that setup, you do not need to specify the path to the roles as Ansible automatically expects roles in the
roles directory relative to the playbook. Then your roles section in the playbook is much cleaner:
Instead of defining global variables to trigger actions inside roles you can use two other approaches.
1. role parameters
Roles can have parameters. If you want to pass parameters you simply have to convert it to a dictionary:
- role: monitor
sensu_install_server then are available only in the role
monitor. This is a litte more cleaner and also makes it clear to anybody these vars will be used in this role, not in the
Tags actually are the way how to trigger specific parts of a playbook/roles. Tags though are passed from the command line and not by hardcoded variables in the playbook. Imagine your role
main.yml looks like this:
- include: common.yml
- include: server.yml
- include: client.yml
always is special and will run the tagged tasks... well you guessed it... always.
Now you would call your playbook like this:
ansible-playbook monitor.yml --tags server
ansible-playbook monitor.yml --tags client
Or if you want to run both you even could do:
ansible-playbook monitor.yml --tags "client,server"
If you use this, don't forget to tag your users role accordingly, or it will not be ran at all.
If you do not specify any
--tags all tasks are executed, if you want to filter specific tags you can use the
ansible-playbook monitor.yml --skip-tags "server"
You could even filter the always tag.
ansible-playbook monitor.yml --tags "server" --skip-tags "always"