仅当其他资源应用更改时 Puppet 才触发资源?
Puppet trigger resource only if other resource applied a change?
我有一个这样的 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
资源仅在 vcsrepo
资源在 github 上找到更新并进行更改时才重新启动设备应用程序。
单独使用 puppet 是否可行,或者我应该编写一个 bash 脚本来检查上次更新 .git
文件夹的时间?
您可以将元参数 subscribe
和参数 refreshonly
与您的 exec
资源一起使用来完成此操作。
首先,使用 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,
}
答案对我不起作用。由于“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,
}
我有一个这样的 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
资源仅在 vcsrepo
资源在 github 上找到更新并进行更改时才重新启动设备应用程序。
单独使用 puppet 是否可行,或者我应该编写一个 bash 脚本来检查上次更新 .git
文件夹的时间?
您可以将元参数 subscribe
和参数 refreshonly
与您的 exec
资源一起使用来完成此操作。
首先,使用 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,
}
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,
}