Ask Your Question

Execute command after a package is installed

asked 2013-09-20 15:05:13 -0600

Rob Ogilvie gravatar image

Good Afternoon-

I'm stumped a bit. I need to execute a command after a package is installed, and only if the package was installed just.

If the package is already there, I don't want it to execute.

I have the package:

 package { "splunk":
        name => $splunkpackagename,
        ensure => latest,
        source => "/storage/ovm/packages/${splunkpackagename}-5*rpm",
        provider => 'rpm',

...and defined an untested class for the exec so it doesn't always run:

class splunkfirstrun {
        exec { "/opt/splunkforwarder/bin/splunk start --accept-license --no-prompt --answer-yes" }

How can I best skin this cat?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2013-09-20 17:35:40 -0600

Ancillas gravatar image

updated 2013-09-20 17:45:48 -0600

Firstly, here's the documenation on resource relationships.

The solution that doc75 created will work, but I would use a dependency chain. As the number of resources in your manifest grow, the subscribe, before, require, and notify meta-parameters become confusing because when you insert a new resource in between two others, all of the relationships change. With chaining, it's easier, and it keeps your resources clean.

That being said, I don't think you need a notify/subscribe chain here. I think you need to utilize the boot-start flag of the puppet binary so that it generates init scripts ... (more)

edit flag offensive delete link more

answered 2013-09-20 16:16:00 -0600

doc75 gravatar image


You could probably do something like this (not tested):

package { "splunk":
        name => $splunkpackagename,
        ensure => latest,
        source => "/storage/ovm/packages/${splunkpackagename}-5*rpm",
        provider => 'rpm',

exec { "/opt/splunkforwarder/bin/splunk start --accept-license --no-prompt --answer-yes; touch /path_to_persistent_dir/splunk_exec_done.txt":
        creates => '/path_to_persistent_dir/splunk_exec_done.txt',
        refreshonly => true,
        subscribe => Package['splunk'],

Not sure that this is the nicer solution to what you want to do ;-)

edit flag offensive delete link more


Rob Ogilvie, did this work for you? I'm working on the same thing: "execute a command after a package is installed"

chanslor gravatar imagechanslor ( 2018-01-04 08:08:56 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2013-09-20 15:05:13 -0600

Seen: 11,443 times

Last updated: Sep 20 '13