FreeBSD 14
Sponsored Link

Puppet : How to use [exec Resource]2024/09/12

 

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.
root@dlp:~ #
vi /usr/local/etc/puppet/code/environments/production/manifests/cmd01.pp
file { '/home/test2.txt':
  ensure => file,
  owner  => 'root',
  group  => 'wheel',
  mode   => '0644',
    source => 'puppet://dlp.srv.world/extra_files/test2.txt'
}

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

root@dlp:~ #
echo "Puppet test file" > /usr/local/etc/puppet/files/test2.txt
Matched Content