Ask Your Question
2

notify and subscribe with refreshonly not working in exec resource

asked 2015-05-04 05:57:58 -0600

Chutki gravatar image

Hi,

I have following manifests

file { '/opt/dir/install.sh':
    ensure => present,
    source => "......",
    notify => Exec['install_packgae']
  }

 exec {"install_package":
    cwd     => '/opt/dir/bin',
    path    => '/opt/dir/bin' ,
    command => "install.sh -i",
    unless  => "/bin/rpm -q package_name",
    refresh => 'true,
    notify  => Exec['cmdagent_script']
  }


  exec {'cmdagent_script':
    cwd     => '/opt/agent/bin',
    path    => '/opt/agent/bin',
    command => 'cmdagent -p',
    refresh => 'true,
 }

I have problem with exec {'cmdagent_script' , I want this resource to run only if exec {"install_package" has any change (when exec {"installpackage it runs). but exec {'cmdagentscript' run each and every time though exec {"install_package' doesn't run.

I tried the below option as well with "subsribe"

exec {"install_package":
    cwd     => '/opt/dir/bin',
    path    => '/opt/dir/bin' ,
    command => "install.sh -i",
    unless  => "/bin/rpm -q package_name",
    refresh => 'true,

  }


  exec {'cmdagent_script':
    cwd     => '/opt/agent/bin',
    path    => '/opt/agent/bin',
    command => 'cmdagent -p',
    refresh => 'true,
   subscribe => Exec['install_package']
 }

but again exec{cmagent_script run on each and every run.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
4

answered 2015-05-04 14:50:41 -0600

JohnsonEarls gravatar image

updated 2015-05-04 14:51:59 -0600

You need to use refreshonly, not refresh:

file { '/opt/dir/install.sh':
  ensure => present,
  source => "......",
  notify => Exec['install_package']
}

exec {"install_package":
  cwd     => '/opt/dir/bin',
  path    => '/opt/dir/bin' ,
  command => "install.sh -i",
  unless  => "/bin/rpm -q package_name",
  refreshonly => true,
  notify  => Exec['cmdagent_script']
}

exec {'cmdagent_script':
  cwd     => '/opt/agent/bin',
  path    => '/opt/agent/bin',
  command => 'cmdagent -p',
  refreshonly => true,
}

The refresh option gives an alternate command to run instead of command when the exec is being triggered by a notify. refreshonly says to only run the exec when it is triggered by a notify - that's what you're looking for.

edit flag offensive delete link more

Comments

It worked :)

Chutki gravatar imageChutki ( 2015-05-04 23:26:53 -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

Stats

Asked: 2015-05-04 05:57:58 -0600

Seen: 18,043 times

Last updated: May 04 '15