如何编写资源集合依赖
How to write a resource collection dependency
在食谱中 nginx
我使用 service
资源。
service 'nginx' do
supports status: true, restart: true, reload: true
action [:enable, :start]
end
而在另一个食谱 foo
中,使用了 notifies :reload, 'service[nginx]'
。
当我 运行 两种食谱或仅 nginx
时,效果很好。
但是当只有 foo
在 run_list
中时,它会失败并显示错误 service[nginx] cannot be found in the resource collection.
目前,当我只想 运行 foo
.
时,我正在使用此命令
knife solo cook my_server --override-runlist "nginx,foo`
我在foo/metadate.rb
中添加了depends 'nginx'
,但没有解决问题。
如何指定这样的依赖项?
您需要元数据中的 depends
和 foo/recipes/default.rb
顶部的 include_recipe 'nginx'
。你不能只是 运行 recipe[foo::default]
因为它对现有的服务资源有很大的依赖。
这将是一个很好的例子,说明为什么覆盖 运行 列表有点难以使用,并且在编写复杂代码时有点崩溃。另一个选项会稍微复杂一些,在 foo 配方中检查资源是否存在于集合中,如果不存在则创建一个存根(什么也不做),但这超出了我想要描述的范围如果你不太了解 Chef 的内幕。
在食谱中 nginx
我使用 service
资源。
service 'nginx' do
supports status: true, restart: true, reload: true
action [:enable, :start]
end
而在另一个食谱 foo
中,使用了 notifies :reload, 'service[nginx]'
。
当我 运行 两种食谱或仅 nginx
时,效果很好。
但是当只有 foo
在 run_list
中时,它会失败并显示错误 service[nginx] cannot be found in the resource collection.
目前,当我只想 运行 foo
.
knife solo cook my_server --override-runlist "nginx,foo`
我在foo/metadate.rb
中添加了depends 'nginx'
,但没有解决问题。
如何指定这样的依赖项?
您需要元数据中的 depends
和 foo/recipes/default.rb
顶部的 include_recipe 'nginx'
。你不能只是 运行 recipe[foo::default]
因为它对现有的服务资源有很大的依赖。
这将是一个很好的例子,说明为什么覆盖 运行 列表有点难以使用,并且在编写复杂代码时有点崩溃。另一个选项会稍微复杂一些,在 foo 配方中检查资源是否存在于集合中,如果不存在则创建一个存根(什么也不做),但这超出了我想要描述的范围如果你不太了解 Chef 的内幕。