Debian 12 bookworm
Sponsored Link

Puppet : How to use [exec Resource]2023/08/10


This is the examples for [exec] resource.

It is possible to execute any commands by using [exec] resource, however it is not recommended because it is critical. So use this resource for specific case like when it receives events by using the refreshonly parameter.

[1] It executes [echo "copy test2.txt" | tee /home/copy-test2.txt] only when [/home/test2.txt] is updated.
vi /etc/puppet/code/environments/production/manifests/cmd01.pp
file { '/home/test2.txt':
  ensure => file,
  owner  => 'root',
  group  => 'root',
  mode   => '0644',
    source => 'puppet://'

exec { 'echo "copy test2.txt" | tee /home/copy-test2.txt':
  path        => ['/usr/bin', '/usr/sbin'],
  subscribe   => File['/home/test2.txt'],
  refreshonly => true
Matched Content