Ask Your Question
0

exec not triggering with subscribe and notify

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

Chutki gravatar image

Hi,

I have below manifests

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

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

I am getting

Notice: /Stage[main]/module_name/File'/root/test_install.sh']/ensure: defined content as '{md5}7b565873ed67a5bf3b9d789dde3c9363'
Info: /Stage[main]/module_name/File'/root/test_install.sh']: Scheduling refresh of Exec[install_script]
Info: /Stage[main]/module_name/File'/root/test_install.sh']: 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

Comments

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 (https://github.com/jordansissel/fpm/wiki/) to create one yourself and manage it with a package{}.

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

1 Answer

Sort by ยป oldest newest most voted
0

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

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/install.sh 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 install.sh -i that's located in the /root/test_install.sh directory, rather than running the test_install.sh 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/test_install.sh -i",
    refresh_only => true,
   }

and see if that does what you expect

edit flag offensive delete link more

Comments

I added "cwd"attribute and it worked.

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

Stats

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

Seen: 2,292 times

Last updated: Apr 30 '15