问题描述
如何将 Exec 配置为仅在另一个 Exec 运行时运行?
how can I configure a Exec to run only if another Exec ran?
我有一个这样的清单:
file { $target:
ensure => directory
}
exec { "unzip foobar.zip -C ${target}":
unless => "file ${target}/some-file-form-archive"
}
exec { "chown -R $user ${target}":
onlyif => ???
}
我希望 chown
仅在 unzip foobar.zip
运行时运行.当然,我可以开始检查 some-file-from-archive
是否已经归 $user
所有,但不知何故似乎不对.
I would like the chown
to run only if unzip foobar.zip
ran. Of course I could start checking whether some-file-from-archive
is already owned by $user
, but somehow it does not seem right.
推荐答案
这里已经有了答案:http://ask.puppetlabs.com/question/14726/run-exec-only-if-another-exec-ran/
像这样更改清单可以解决我的问题:
Changing the manifest like this fixes my problem:
exec { 'unpack file':
command => "unzip foobar.zip -C ${target}",
path => '/usr/bin',
creates => "${target}/some-file-form-archive",
require => File[$target, '<archive>'],
notify => Exec[fix archive],
}
exec { 'fix archive':
command => "chown -R ${user} ${target}",
path => '/bin',
refreshonly => true,
}
更新 28.11.2014
受到 Felix Frank 的评论的启发,我试过了出别的东西.您可以确保文件树中的所有资源都由这样的用户拥有,而不是通知/刷新:
motivated by Felix Frank's comment i tried out something else. instead of notify/refreshonly you can ensure all resource in a file-tree are owned by a user like this:
exec { 'fix archive':
command => "chown -R ${user} ${target}",
path => '/bin',
unless => "test 0 -eq $(find ${target} \\! -user ${user} | wc -l)"
}
这种方式确保所有者是 $user
,即使它在 unpack file
运行后被更改.
this way owner is ensured to be $user
even if it was changed after unpack file
ran.
这篇关于仅当另一个 Exec 运行时才运行 Exec的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!