Sometimes one Puppet class needs to know about another or at least, to know whether or not it's present. For example, a class that manages the firewall may need to know whether or not the node is a web server.
Puppet's tagged
function will tell you whether a named class or resource is present in the catalog for this node. You can also apply arbitrary tags to a node or class and check for the presence of these tags.
To help you find out if you're running on a particular node or class of node, all nodes are automatically tagged with the node name and the names of any parent nodes they inherit from. Here's an example which shows how to use tagged
to get this information:
Add the following code to your
manifests/nodes.pp
file (replacingcookbook
with your machine's hostname):node 'bitfield_server' { } node 'cookbook' inherits 'bitfield_server' { if tagged('cookbook') { notify { 'this will succeed': } } if tagged('bitfield_server') { notify { 'so will this...