Resource examples
Resource declaration
This example resource declaration includes:
file
: The resource type.ntp.conf
: The resource title.path
: An attribute.'/etc/ntp.conf'
: The value of an attribute; in this case, a string.template('ntp/ntp.conf')
: A function call that returns a value; in this case, thetemplate
function, with the name of a template in a module as its argument.
file { 'ntp.conf': path => '/etc/ntp.conf', ensure => file, content => template('ntp/ntp.conf'), owner => 'root', mode => '0644', }
For details about resources and resource declaration syntax, see Resources.
Resource relationship metaparameters
Two resource declarations establishing relationships with the before
and subscribe
metaparameters, which accept resource references.
The first declaration ensures that the ntp
package is installed
before the ntp.conf
file is created. The second declaration ensures
that the ntpd
service is notified of any changes to the
ntp.conf
file.
package { 'ntp': ensure => installed, before => File['ntp.conf'], } service { 'ntpd': ensure => running, subscribe => File['ntp.conf'], }
For details about relationships usage and syntax, see Relationships and ordering. For details about resource references, see Resource and class references.
Resource relationship chaining arrows
Chaining arrows forming relationships between three resources, using resource
references.In this example, the ntp
package must be installed
before the ntp.conf
file is created; after the file is created, the
ntpd
service is notified.
Package['ntp'] -> File['ntp.conf'] ~> Service['ntpd']
For details about relationships usage and syntax, see Relationships and ordering. For details about resource references, see Resource and class references.
Exported resource declaration
An exported resource declaration.
@@nagios_service { "check_zfs${hostname}": use => 'generic-service', host_name => "$fqdn", check_command => 'check_nrpe_1arg!check_zfs', service_description => "check_zfs${hostname}", target => '/etc/nagios3/conf.d/nagios_service.cfg', notify => Service[$nagios::params::nagios_service], }
For information about declaring and collecting exported resources, see Exported resources.
Resource collector
A resource collector, sometimes called the "spaceship operator." Resource collectors select a group of resources by searching the attributes of each resource in the catalog.
User <| groups == 'admin' |>
For details about resource collector usage and syntax, see Resource collectors.
Exported resource collector
An exported resource collector, which works with exported resources, which are available for use by other nodes.
Concat::Fragment <<| tag == "bacula-storage-dir-${bacula_director}" |>>
For details about resource collector usage and syntax, see Resource collectors. For information about declaring and collecting exported resources, see Exported resources.
Resource default for the exec type
A resource default statement set default attribute values for a given resource type.
This example specifies defaults for the exec
resource type attributes path
, environment
,
logoutput
, and timeout
.
Exec { path => '/usr/bin:/bin:/usr/sbin:/sbin', environment => 'RUBYLIB=/opt/puppetlabs/puppet/lib/ruby/site_ruby/2.1.0/', logoutput => true, timeout => 180, }
For details about default statement usage and syntax, see Resource defaults.
Virtual resource
A virtual resource, which is declared in the catalog but isn't applied to a system unless it is explicitly realized.
@user { 'deploy': uid => 2004, comment => 'Deployment User', group => www-data, groups => ["enterprise"], tag => [deploy, web], }
For details about virtual resource usage and syntax, see Virtual resources.