我已经成功地使用AWS部署了我的应用程序,现在我正在尝试实现一个自定义厨师食谱,它将允许我设置OpsWorks环境变量。我已经设置了Git代码库,食谱正在用OpsWorks更新。我在我的dev box上使用刀子命令生成了这本食谱,它实际上就是一个包含几行代码的recipes/default.rb文件的目录结构。
当我尝试做像下面这样的事情时,我似乎总是收到错误
node[:deploy].each do |application, deploy|
deploy = node[:deploy][application]
command "ls -la"
end(注: ls -la仅用于测试,我知道这不会设置环境变量)
我得到以下错误:ERROR: Caught exception during execution of custom recipe: xyz-enviroment: NoMethodError - undefined method command' for #<Chef::Recipe:0x7feb59200c00> - /opt/aws/opsworks/releases/20130328224322_109/vendor/bundle/ruby/1.8/gems/chef-0.9.15.5/bin/../lib/chef/mixin/recipe_definition_dsl_core.rb:56:in method_missing
另外,如果我尝试像这样的东西
execute "setting up the enviroment" do
# TODO: Add code that does something here
end我得到以下错误:
execute[setting up the enviroment] (/opt/aws/opsworks/current/site-cookbooks/xyz-enviroment/recipes/default.rb:18:in `from_file') had an error:
No such file or directory - setting up the enviroment我对Chef是个新手,所以我确信我做错了一些简单的事情,我只是一直没能弄清楚。提前感谢你的帮助。
发布于 2013-04-09 22:25:36
在看到下面的回复之前,我已经解决了我的问题,他们可能已经解决了问题,但我现在没有时间回去尝试。
我的解决方案是使用Chef模板创建一个初始化器文件,以便在rails启动应用程序时设置变量。
# deafult.rb
node[:deploy].each do |application, deploy|
deploy = node[:deploy][application]
execute "restart Rails app #{application}" do
cwd deploy[:current_path]
command node[:opsworks][:rails_stack][:restart_command]
action :nothing
end
template "#{deploy[:deploy_to]}/current/config/initializers/dev_enviroment.rb" do
source "dev_enviroment.erb"
cookbook 'dev-enviroment'
group deploy[:group]
owner deploy[:user]
variables(:dev_env => deploy[:dev_env])
notifies :run, resources(:execute => "restart Rails app #{application}")
only_if do
File.exists?("#{deploy[:deploy_to]}") && File.exists?("#{deploy[:deploy_to]}/current/config/")
end
end
enddev_enviroment.erb
ENV['VAR1'] = "<%= @dev_env[:VAR1] %>"
ENV['VAR2'] = "<%= @dev_env[:VAR2] %>"Opsworks堆栈层中使用的自定义Chef JSON:
{
"deploy": {
"myapp": {
"dev_env": {
"VAR1": "INFO1",
"VAR2": "INFO2",
}
}
}
}发布于 2013-04-09 09:10:25
您没有指定要运行的命令,因此它实际上正在尝试运行setting up the environment,这不是一个有效的命令。
请尝试在块内指定command属性:
execute "setting up the enviroment" do
command "/path/to/command --flags"
end或者,将资源名称设置为命令本身:
execute "/path/to/command --flags" do
# TODO: Add code that does something here
end发布于 2013-04-09 09:42:13
您的第二个问题已被clb正确回答。对于第一个,'command‘不是一个有效的厨师资源,你需要类似这样的东西:
node[:deploy].each do |application, deploy|
deploy = node[:deploy][application]
execute "running a command for #{application}" do
command "ls -la"
end
endhttps://stackoverflow.com/questions/15887636
复制相似问题