Resource tags are metaparameters available to all resources in Puppet. They are used in collecting only and do not affect the definition of resources.
Metaparameters are part of how Puppet compiles the catalog and not part of the resource to which they are attached. Metaparameters include before
, notify
, require
, and subscribe
. More information on metaparameters is available at http://docs.puppetlabs.com/references/latest/metaparameter.html.
Any tags explicitly set on a resource will be appended to the array of tags. In our previous example, we saw the tags for our host entry in the PostgreSQL output as follows, but we didn't address what the tags meant:
{server,ldap,host,class,ldap::server,default,node,ldap-ldapserver1}
All these tags are defaults set by Puppet. To illustrate how tags are used, we can create multiple exported host entries with different tags. We'll start with adding a tag search to our Host
collector in the base
class as follows:
Host <<| tag == 'ldap-server' |>>
Then we'll add an ldap-client
exported host resource to the base
class with the tag 'ldap-client'
as follows:
@@host {"ldap-client-$::hostname": host_aliases => ["$::fqdn","another-$::hostname"], ip => "$::ipaddress", tag => 'ldap-client', }
Now all nodes will only collect Host
resources marked as ldap-server
. Every node will create an ldap-client
exported host resource; we'll add a collector for those to the ldap::server
class:
Host <<| tag == 'ldap-client' |>>
One last change: we need to make our ldap-server
resource-specific, so we'll add a tag to it in ldap::server
as follows:
@@host {"ldap-$::hostname": host_aliases => ["$::fqdn",'ldap'], ip => "$::ipaddress", tag => 'ldap-server', }
Now every node with the ldap::server
class exports a host resource tagged with ldap-server
and collects all host resources tagged with ldap-client
. After running Puppet on master and client nodes 1 and 2, we see the following on our ldapserver1
as the host resources tagged with ldap-client
get defined:
3.12.136.63