Puppet – Exec only if a certain condition is true

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

Advertisements

One thought on “Puppet – Exec only if a certain condition is true”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s