Puppet trigger resource only if other resource applied a change?

泪湿孤枕 提交于 2021-01-28 05:05:13

问题


I have a pp manifest like this:

vcsrepo { '/home/pi/pop_machine':
  ensure   => latest,
  provider => git,
  source   => 'https://github.com/kirkins/pop-machine-demo.git',
  revision => 'master',
}

exec { 'npm start':
  command => "/usr/bin/killall electron & /usr/bin/npm start",
  cwd     => "/home/pi/pop_machine/",
}

I want the exec resource to restart the device application only if the vcsrepo resource found an update on github and made changes.

Would this be possible with puppet alone, or should I write a bash script to check the last time the .git folder was updated?


回答1:


You can use the metaparameter subscribe and parameter refreshonly with your exec resource to accomplish this.

First, use the subscribe metaparmeter to establish an ordering relationship of the exec on the vcsrepo and to also check for a resource change: https://docs.puppet.com/puppet/latest/metaparameter.html#subscribe

Next, use refreshonly to instruct the exec resource to only apply a change if the vcsrepo repo effected a change (vis a vis non-idempotent): https://docs.puppet.com/puppet/latest/types/exec.html#exec-attribute-refreshonly

It would look like:

vcsrepo { '/home/pi/pop_machine':
  ensure   => latest,
  provider => git,
  source   => 'https://github.com/kirkins/pop-machine-demo.git',
  revision => 'master',
}

exec { 'npm start':
  command     => "/usr/bin/killall electron & /usr/bin/npm start",
  cwd         => "/home/pi/pop_machine/",
  subscribe   => Vcsrepo['/home/pi/pop_machine'],
  refreshonly => true,
}


来源:https://stackoverflow.com/questions/45918630/puppet-trigger-resource-only-if-other-resource-applied-a-change

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!