I’m trying to figure out when and how best to use role dependencies.
Currently I have a single role for handling my Postfix configuration on ALL my hosts; some are classified as ‘mail-servers’ and the rest as ‘mail-clients’. Depending upon a role variable (‘mailserver_class’) I can set when I call the role, I ether get one set of Postfix configuration files or the other.
My site-role.yml currently looks like this:
-
hosts: all:!mail-servers
roles: -
{ role: postfix, tags: [mail-client] }
-
hosts: mail-servers
roles: -
{ role: postfix, tags: [mail-server], mailserver_class: server }
This works for me. however, I can see accomplishing basically the same thing by creating ‘mail-client’ and ‘mail-server’ roles that both call ‘postfix’ as a role dependency, such as:
site-role.yml:
-hosts: all:!mail-servers
roles:
- mail-client
-hosts: mail-servers
roles:
- mail-servers
roles/mail-server/meta/main.yml:
dependencies:
- { role: postfix }
roles/mail-server/meta/main.yml:
dependencies:
- { role: postfix, mailserver_class: server }
To me, it seems that setting up actual ‘mail-client’ and ‘mail-server’ roles each with a dependency on the ‘postfix’ role is more work and I’m not sure I really gain anything in this case. On the other hand, by defining these two roles, I can probably have my different Postfix configuration templates live under those roles and probably not need the ‘mailserver_class’ variable. [To be perfectly honest, my gut instinct is to have everything in the Postfix role and then have internal logic determine which config file to use - separating the configs to different role just feel very, very wrong to me.]
So, what thoughts do you have on these layouts? It feels like I can accomplish the same thing with either layout. I wanted to see what other people thought about these two cases and what advantages or disadvantages each layout offered. Your thoughts are appreciated.
thx
Chris.