AWS Opsworks 在 Deploy 配方上使用 "environment_variables"

AWS Opsworks using "environment_variables" on Deploy recipes

我想使用应用程序的 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 

如果我还没有部署任何应用程序,运行 安装后的部署方法的目的是什么???如果 environment_variables 不在 Deploy 配方中,可以在哪里使用???

想象一下,您已设置好所有内容,并且刚刚启动了一台新机器。它将 运行 安装、配置然后部署,否则您最终会得到一个尚未准备好用于生产的实例。

当您尝试访问未设置的属性时部署失败

您可以使用http://ruby-doc.org/core-1.9.3/Hash.html#method-i-has_key-3F检查这个

例如

if node[:deploy].has_key?("ws")

end

你的环境变量也一样