仅当其他资源应用更改时才触发木偶资源?

  • 本文关键字:资源 其他 应用 puppet
  • 更新时间 :
  • 英文 :


我有一个这样的pp清单:

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资源仅在 github 上找到更新并进行更改时重新启动设备应用程序vcsrepo

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

您可以将元参数subscribe和参数refreshonlyexec资源一起使用来完成此操作。

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

接下来,使用refreshonly指示exec资源仅在vcsrepo存储库生效更改(相对于非幂等(时才应用更改: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,
}

Matt Schuchard的回答对我不起作用。 由于"exec"中的"订阅",我一直收到来自puppet的错误:

Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Could not autoload puppet/type/vcsrepo: Attempt to redefine entity 'http://puppet.com/2016.1/runtime/type/vcsrepo'.

但这确实对我有用:

vcsrepo { '/home/pi/pop_machine':
ensure   => latest,
provider => git,
source   => 'https://github.com/kirkins/pop-machine-demo.git',
revision => 'master',
notify   => Exec['npm start'],
}
exec { 'npm start':
command     => "/usr/bin/killall electron & /usr/bin/npm start",
cwd         => "/home/pi/pop_machine/",
refreshonly => true,
}

最新更新