我想使用app的environment_variables来设置一些属性,但我的实例在安装时仍然失败,阅读文档(http://docs.aws.amazon.com/opsworks/latest/userguide/workingcookbook-events.html)我发现了这个:
"Setup includes Deploy; it runs the Deploy recipes after setup is complete.".
这是我的部署脚本的一部分
if node['deploy']['ws']['application'] && node['deploy']['ws']['environment_variables']['is_root_app'] == 'true'
web_app node['deploy']['ws']['application'] do
server_name node['fqdn']
server_aliases node['deploy']['ws']['domains']
template 'web_app.conf.erb'
docroot node.default['apache']['docroot_dir']
ssl_enabled node['deploy']['ws']['ssl_support']
enable true
end
end
这是安装日志
NoMethodError
-------------
undefined method `[]' for nil:NilClass
Cookbook Trace:
---------------
/var/chef/runs/254b8caa-cd70-4525-a2fd-71044afdf62d/local-mode-cache/cache/cookbooks/WebService/recipes/deploy_app.rb:8:in `from_file'
Relevant File Content:
----------------------
/var/chef/runs/254b8caa-cd70-4525-a2fd-71044afdf62d/local-mode-cache/cache/cookbooks/WebService/recipes/deploy_app.rb:
1: #
2: # Cookbook Name:: WebService
3: # Recipe:: default
4: #
5: # Copyright (c) 2016 The Authors, All Rights Reserved.
6:
7:
8>> if node['deploy']['ws']['application'] && node['deploy']['ws']['environment_variables']['is_root_app'] == 'true'
9: web_app node['deploy']['ws']['application'] do
10: server_name node['fqdn']
11: server_aliases node['deploy']['ws']['domains']
12: template 'web_app.conf.erb'
13: docroot node.default['apache']['docroot_dir']
14: ssl_enabled node['deploy']['ws']['ssl_support']
15: enable true
16: end
17: else
如果我没有部署任何App,那么在安装后运行Deploy配方的目的是什么?如果不是在部署配方???
上可以使用environment_variables答案 0 :(得分:1)
想象一下,您已经完成了所有设置,并且您只需启动一台新机器。它将运行setup,configure然后部署,否则你最终会得到一个尚未准备好生产的实例。
当您尝试访问未设置的属性时,部署失败
您可以使用http://ruby-doc.org/core-1.9.3/Hash.html#method-i-has_key-3F来检查
e.g。
if node[:deploy].has_key?("ws")
end
您的env变量相同