【问题标题】:Chef: Why I cannot access the attributes defined in Role?厨师:为什么我不能访问角色中定义的属性?
【发布时间】:2014-02-26 01:40:46
【问题描述】:

我使用的是 Chef 11.8.2,带有开源 Chef 服务器 我的角色和说明书文件中有以下陈述:

roles/webserver.rb

name "webserver"
description "Web Servers"
run_list %w{recipe[my_cookbook]}
default_attributes({
     "company" => "OPSCODE"
})

cookbooks/my_cookbook/recipes/default.rb

puts node.default.inspect

它只打印“{}”。我检查了节点是否正确分配给角色 webserver:

C:\chef\chef-repo>knife node show chef-client-1
Node Name:   chef-client-1
Environment: dev
FQDN:        chef-client-1.puncha.com
IP:          192.168.1.31
Run List:    role[webserver]
Roles:       webserver
Recipes:     my_cookbook
Platform:    ubuntu 12.10
Tags:

【问题讨论】:

  • 你是否至少收敛过一次节点?
  • 是的,至少收敛(运行 chef-client)节点一次,并在上面的刀命令中添加“-l”参数,以检索所有节点属性。

标签: chef-infra chef-recipe


【解决方案1】:

您想检查“编译”属性,而不是默认属性:

puts node.inspect

【讨论】:

  • 谢谢。现在我明白了,要在配方中使用属性,我应该在节点对象上使用已编译的属性,而不是 node.default。
猜你喜欢
  • 1970-01-01
  • 2015-05-08
  • 1970-01-01
  • 2013-11-03
  • 1970-01-01
  • 2014-12-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多