0

我正在尝试创建一个厨师食谱,它将根据使用我的应用程序源代码从 git 存储库下载的 yaml 文件的内容动态创建资源。到目前为止我有这个:

git "/home/a_user/#{ node[:my_node][:application] }" do
  repository node[:my_node][:git_repository]
  revision node[:my_node][:git_branch]
  action :sync
  user "a_user"
  group "a_user"
end

require 'yaml'

ruby_block "load the process into the node" do
  block do
     yml = YAML::load(File.open("/home/a_user/#{node[:my_node][:application]}/processes.yml"))
     node.set[:my_node][:worker][:processes] = yml[:processes]
  end
  subscribes :create, "git[/home/a_user/#{ node[:my_node][:application] }]" :immediately
end



node[:my_node][:worker][:processes].each do | name, cmd |
   supervisor_service name do
     command "bash -c \"source /home/a_user/.profile && #{ cmd }\""
     action :enable
   end   
 end 

 service "supervisor" do
    action :restart
 end  

yaml 文件格式为:

processes:
    process_a: python myscript.py --a
    process_b: python myscript.py --b

但是,当我执行它时,node[:my_node][:worker][:processes]编译阶段的值为空,因此主管资源不会在执行阶段执行。

有人可以给我一个关于如何完成这项工作的指导吗?我遗漏了一些明显的东西,还是我做错了?

4

1 回答 1

0

在编译阶段填充属性:

git "/home/a_user/#{ node[:my_node][:application] }" do
  repository node[:my_node][:git_repository]
  revision node[:my_node][:git_branch]
  action :nothing
  user "a_user"
  group "a_user"
end.run_action(:sync)

ruby_block "load the process into the node" do
  block do
     yml = YAML::load(File.open("/home/a_user/#{node[:my_node][:application]}/processes.yml"))
     node.set[:my_node][:worker][:processes] = yml[:processes]
  end
  subscribes :create, "git[/home/a_user/#{ node[:my_node][:application] }]" :immediately
  action :nothing
end.run_action(:create)
于 2014-02-28T16:34:02.260 回答