I have question whether is possible to run task only if server belong to specific group?
— Quick scenario —
Lets say that on Inventory I have:
[targets]
srv01
srv02
[webservers]
srv01
Now I would like to play ‘common’ roles with tasks following (pseudo code):
name: Do something
action: Ansible - action
when: server is in webservers group.
I know that is possible run another play which runs only on webserves but not quite sure whether this suits to my issue:
— Long scenario —
I have to cofigure a lot servers belongs to specific groups (web servers / db servers) and munin plugins have some common plugins / and depends of group (www / db).
When one is installing munin-node from RPM (RH based systems) a lot of munin-plugins are created:
Now common role from ansible - removes not requried plugins - restarting munin-node
Then some additional plugins should be configured for server belongs to group www/db
Do I would like to avoid situation that: Common plugin removes not required plugins from munin-node (including those for www - like apache), and then another play install this back.
I woud really achive somethign like that:
name: Remove not required munin plugins
action:
when: Server not belong to group WWW
…
name: Add plugins for WWW
action:
when: Server belong to group WWW
Are you sure that this is working - just tested on ansible 1.3 and I have error:
ERROR: Syntax Error while loading YAML script, /src/ansible/roles/mysql-munin/tasks/main.yml
Note: The error may actually appear before this position: line 34, column 27
mysql_seconds_behind_master
when: ‘dbslave’ in group_names
^
I created special role: mysql-munin
There are 3 tasks which should be run - 2 of them on DB master - 1 on DB slave.
But so far I am struggeling to run task only on server which belongs to specific group.
Tasks list:
play #3 (Database | Configurtion for database servers):
MySQL-munin | Create Munin configuration - Template # Should run on DB servers
MySQL-munin | Link Official munin plugins # Should run on DB servers
MySQL-munin | Link Custom munin plugins # Should run ONLY on Slave DB server