【问题标题】:AWS Opsworks using "environment_variables" on Deploy recipesAWS Opsworks 在部署配方上使用“environment_variables”
【发布时间】:2016-04-27 18:42:56
【问题描述】:

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

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

【问题讨论】:

    标签: amazon-web-services chef-infra chef-recipe aws-opsworks


    【解决方案1】:

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

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

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

    例如

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

    环境变量也是如此

    【讨论】:

    • 太好了,我不是 ruby​​ 程序员,谢谢你的提示
    猜你喜欢
    • 2016-09-26
    • 2016-12-16
    • 2015-10-23
    • 2017-08-16
    • 2013-08-07
    • 2015-05-04
    • 1970-01-01
    • 1970-01-01
    • 2015-02-09
    相关资源
    最近更新 更多