this kind of thing would be useful as a role. Is there anyway to include a varfile either directly based on OS, or via a variable name as in the above example?
First – One really should not use “ansible_pkg_manager” because it bypasses with the with_items optimizations that allow yum and apt packages to be installed in the same transaction set.
Second --No, you can’t load roles based on facts, and should not do this.
Rather, two options:
(A)
use the group_by module to select your webservers that are Ubuntu and your webservers that are Fedora (for example) and then apply the appropriate
roles to each,
First -- One really should not use "ansible_pkg_manager" because it
bypasses with the with_items optimizations that allow yum and apt packages
to be installed in the same transaction set.
Was about to ask about odd behaviour if ansible_pkg_manage used, thanks for
explaining.
Second --No, you can't load roles based on facts, and should not do this.
Rather, two options:
(A)
use the group_by module to select your webservers that are Ubuntu and your
webservers that are Fedora (for example) and then apply the appropriate
roles to each,
The group_by method will produce cleaner output when the playbook is run.
In many cases though, you should know what OS each of your servers are, so
many people will not have to worry about dynamic application.
If you have a web farm where some servers are randomly differnet
distributions, I recommend straightening that out
Working for several customers with different distributions, maybe not so
common use case :). So basically, if I want to have clean output, I should
have LAMP-Debian and LAMP-CentOS roles?
I can surely take duplicated code into separate .yml files and share it
between roles, is that 'best practise'?
Yes, definitely sharing common tasks from two different roles is doable and a good way to do it.
In 1.3, James also added role dependencies, which provide a cleaner way to do this, so you could have a fooapp_centos role that requires all the common
parts, but also the right OS specific parts as well.