On Tue, Feb 23, 2016 at 12:41 AM, Tim Dunphy <bluethu...@gmail.com> wrote:
> Craig and Christan.. thanks for your input! What I was trying to do with the > 'refreshonly' statement was to get the exec statement to run only once. > > How would I be able to achieve getting the exec command to run only once? There are a number of "restrictive" attributes that will limit how/when an exec is run. By default, with none of these, an exec will execute every time puppet runs, eg: exec { 'foo': path => "/bin", command => "foo --bar", } In order to stop the exec running on every puppet run, you need to think about when you do, or do not, want to run it. This depends on the nature of your command and what it does. If this command is something that should just run once to achieve a task, but never again once that task has been completed you need to think of a way to test if the task is completed or not. That could be another command you can run to verify if you need to run the exec. This can be achieved with onlyif / unless and takes a command as an argument. command => 'foo --bar' onlyif => 'foo --has-not-run-yet' By adding onlyif, the command foo --has-not-run-yet is issued first, the command foo --bar is only run if the first command returns 0. Conversely, there is also unless which has the oposite behaviour to say that run this command *unless* the first command returns 0. The second way to restrict when the command gets run is to identify a file that the command creates, that is to say, if the file exists, assume that this command has already run and don't run it, that can be done with the creates attribute command => 'foo --bar' creates => '/opt/created/by/foo.txt' This will only run if the file /opt/created/by/foo.txt does not exist. The third way is refreshonly, which you initially has in your exec. Refreshonly will only run the command if a resource that the exec is subscribed to is changed, or if a changed resource notifies the exec. file { '/etc/config': ensure => file, notify => Exec['foo'] } The foo exec will only run if there is a change to the /etc/config file resource. Regards Craig -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/CACxdKhGNuLzOY88L6kc_85mrEug375fo0O1cnOdHu5k7R7n%2BfA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.