Sometimes we would only want to execute some initialization configurations on Puppet agent only on the first of manifest application. One approach is to create a text file and only skip the execution when that file exists.
Here is another example written on the Puppet CookBook.
# run exec only if command in onlyif returns 0. exec { "run_account_purger": command => "/usr/local/sbin/account_purger", onlyif => "grep -c old_account /etc/passwd", } # or run multiple commands - all must succeed for exec to run exec { "run_account_purger": command => "/usr/local/sbin/account_purger", onlyif => [ "grep -c old_account /etc/passwd", "test -d /home/old_account/" ], }
Done =)
Reference: Puppet CookBook – Selective exec running
One thought on “Puppet – Exec only if a certain condition is true”