Chef infra 在Chef中动态创建资源
我正在尝试创建一个chef菜谱,它将根据使用我的应用程序源代码从git存储库下载的yaml文件的内容动态创建资源。到目前为止,我有:Chef infra 在Chef中动态创建资源,chef-infra,aws-opsworks,Chef Infra,Aws Opsworks,我正在尝试创建一个chef菜谱,它将根据使用我的应用程序源代码从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_u
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][:processs]
的值在编译阶段为空,因此在执行阶段不会执行主管资源
有人能给我一个如何使这项工作的指针吗?我遗漏了一些明显的东西,或者只是做错了?在编译阶段填充属性:
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)
您可能想查看我的和。如果你制作了一个插件,这将允许在Yaml中创作食谱。不幸的是,这也需要在编译阶段运行大量其他资源,这已经开始变得非常混乱,并且感觉不到特别的“chefy”。你是否尝试过在
ruby_块上使用lazy
?类似于block lazy{{{yml=YAML::…}}
。更多信息请点击此处: