Ask Your Question

exec not triggering with subscribe and notify

asked 2015-04-30 14:08:10 -0600

Chutki gravatar image


I have below manifests

file { '/root/':
    ensure => present,
    owner  => 'root',
    group  => 'root',
    mode   => '0700',
    source => "puppet:///modules/mymodule/",
    notify    => Exec['install_script']

  exec { 'install_script':
    path      => ['/root/'],
    command   => " -i",
    unless    => "/bin/rpm -qa packae_name",
    subscribe   => File['/root/'],

I am getting

Notice: /Stage[main]/module_name/File'/root/']/ensure: defined content as '{md5}7b565873ed67a5bf3b9d789dde3c9363'
Info: /Stage[main]/module_name/File'/root/']: Scheduling refresh of Exec[install_script]
Info: /Stage[main]/module_name/File'/root/']: Scheduling refresh of Exec[install_script']
Notice: /Stage[main]/module_name/Exec[install_script]: Triggered 'refresh' from 2 events

but the pacakge install is not happening, I couldn't see the installed package when I do "rpm -qa package_name".

Also want to know the "subscribe" will only work whenever the file "test_install" is created else it wont trigger the "exec" resource am i right?

edit retag flag offensive close merge delete


Using file/exec to replace package is generally a non-optimal solution. If you can't get an RPM from the vendor, perhaps look into fpm ( to create one yourself and manage it with a package{}.

rnelson0 gravatar imagernelson0 ( 2015-05-01 07:39:58 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2015-04-30 22:05:57 -0600

JohnsonEarls gravatar image

A few points about this:

  1. You only need one of the notify or subscribe pair - either one will create the link. I don't think having both there will hurt anything until you change one and forget to change the other.
  2. Most of the time, when you're using the nofity/subscribe for an exec, you want the exec to have refresh_only => true set; otherwise it's possible for the exec to run multiple times.
  3. using the notify/subscribe with refresh_only means that your exec will only be applied if the notifying resource applied a change - in this case, if the /root/ file was either missing or different than the module specified.
  4. The path parameter to exec indicates the system path in which to find the command to be run and any other commands invoked by that command. In your setup, you are asking it to run -i that's located in the /root/ directory, rather than running the script itself. Even if a script were to run, because your path does not include /bin, /usr/bin, etc., the script would not be able to find any system commands.

Try changing your exec to:

  exec { 'install_script':
    command   => "/root/ -i",
    refresh_only => true,

and see if that does what you expect

edit flag offensive delete link more


I added "cwd"attribute and it worked.

Chutki gravatar imageChutki ( 2015-05-04 05:43:38 -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

1 follower


Asked: 2015-04-30 14:08:10 -0600

Seen: 2,831 times

Last updated: Apr 30 '15