本文介绍了仅当其他资源应用更改时才触发 Puppet 资源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个像这样的 pp 清单:

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/",
}

我希望 exec 资源仅在 vcsrepo 资源在 github 上找到更新并进行更改时重新启动设备应用程序.

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

这是否可以单独使用 puppet,或者我应该编写一个 bash 脚本来检查 .git 文件夹的上次更新时间?

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

推荐答案

您可以在 exec 中使用元参数 subscribe 和参数 refreshonly资源来实现这一点.

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

首先,使用 subscribe 元参数在 vcsrepo 上建立 exec 的排序关系,并检查资源更改:https://docs.puppet.com/puppet/latest/metaparameter.html#订阅

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

接下来,使用 refreshonly 指示 exec 资源仅在 vcsrepo 存储库影响更改(相对于非-幂等):https://docs.puppet.com/puppet/latest/types/exec.html#exec-attribute-refreshonly

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

它看起来像:

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,
}

这篇关于仅当其他资源应用更改时才触发 Puppet 资源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-09 23:12