I am having a issue of understanding how I could make puppet run a command only if another module/class is installed. I read that Define function could do it, but I did not understand it. Example what I am trying to do:
Lets say I have a module/class SSH and module/class SSH Keys and then I want to run a command in SSH Keys only if SSH module/class is defined in node.
I am doing this for NagiOS, to make sure that NagiOS only monitors those servers that have a module installed that it wants to monitor.
PS: Sorry if I explained it badly.
One possibility is to use tags. When you include a class, Puppet automatically tags the node with class name. For example:
Note that the order of includes is significant. If
ssh_keys
is included beforessh
class, the tag is not necessarily visible. Also, if you are using node inheritance and includingssh
andssh_keys
on different levels, it's not very clear where ssh tag ends up to. If needed, you can tag manually,tag(ssh)
, but that isn't very maintainable.You can use
tagged
function to check if tag is present:This method can also be used in situations like:
You could also have your include ssh_keys within the ssh class itself.
Using tagged works but its hard to scale up things that rely on parse order. Its better to have all your classes either in the same module or included from within the module that requires it. Also remember that 'includes' do not need to be unique, you can include the same thing multiple times.