Puppet – Run exec once only

I want to automate the newrelic-sysmond installation using Puppet and it requires to set the license key in the nrsysmond.cfg and start the agent. And all this steps should happen once only and this can be achieved by creating a text file and only execute if the file does not exist.

Here is the class definition i used in the manifest.

class system::newrelic-sysmond ($licensekey) {
  package { "newrelic-sysmond": ensure => installed, }

  exec { 'Insert newrelic license key':
    command => "nrsysmond-config --set license_key=$licensekey",
    require => Package['newrelic-sysmond'],
    creates => '/etc/newrelic/key_added',
  }

  exec { 'Restart newrelic system monitor':
    command => "/etc/init.d/newrelic-sysmond start",
    require => Exec['Insert newrelic license key'],
    creates => '/etc/newrelic/key_added',
  }

  exec { 'Create the key_added file':
    command => "echo key_added > /etc/newrelic/key_added",
    require => Exec['Restart newrelic system monitor'],
    creates => '/etc/newrelic/key_added',
  }
}

 

Done =)

Advertisement

One thought on “Puppet – Run exec once only”

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 )

Facebook photo

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

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.