Overriding Puppet Resources

Puppet resource collectors can be used to override resources. Although it should be used sparingly, this feature is incredibly useful if you need to change a resource declared in a module or want to conditionally set attribute values.

Example overwriting a managed resource:

File<|title == '/etc/some/config'|> {
  ensure  => file,
  owner   => 0,
  content => 'Some content',
}

Example to conditionally set attribute values:

case $facts[os][family] {
  'Debian': {
    Service<|title == 'systemd-timesyncd'|> {
      ensure => stopped,
    }
  }
  'RedHat': {
    Service<|title == 'systemd-timesyncd'|> {
      ensure => running,
    }
  }
}
 
service { 'systemd-timesyncd':
  enable => true,
}
Previous
Back to Blog