3

私はシェフのバージョン10.16.2を使用し
ています(ルビー形式で)役割があります。クックブックの 1 つで設定された属性にアクセスする必要がある

例えば。

name "basebox"
description "A basic box with some packages, ruby and rbenv installed"

deployers = node['users']['names'].find {|k,v| v['role'] == "deploy" }

override_attributes {
  {"rbenv" => {
      "group_users" => deployers
    }
  }
}

run_list [ 
          "recipe[users]",
          "recipe[packages]",
          "recipe[nginx]",
          "recipe[ruby]"
         ]

私はchef-soloを使用しているので、http://wiki.opscode.com/display/chef/Search#Search-FindNodeswithaRoleintheExpandedRunListで指定されている検索を使用できません

ロール定義のノード属性にアクセスするにはどうすればよいですか?

4

2 に答える 2

2

Roles are JSON data.

That is, when you upload the role Ruby file to the server with knife, they are converted to JSON. Consider this role:

name "gaming-system"
description "Systems used for gaming"
run_list(
  "recipe[steam::installer]",
  "recipe[teamspeak3::client]"
)

When I upload it with knife role from file gaming-system.rb, I have this on the server:

{
  "name": "gaming-system",
  "description": "Systems used for gaming",
  "json_class": "Chef::Role",
  "default_attributes": {
  },
  "override_attributes": {
  },
  "chef_type": "role",
  "run_list": [
    "recipe[steam::installer]",
    "recipe[teamspeak3::client]"
  ],
  "env_run_lists": {
  }
}

The reason for the Ruby DSL is that it is "nicer" or "easier" to write than the JSON. Compare the lines and syntax, and it's easy to see which is preferable to new users (who may not be familiar with JSON).

That data is consumed through the API. If you need to do any logic with attributes on your node, do it in a recipe.

于 2012-12-06T16:12:49.050 に答える
0

Not sure if I 100% follow, but if you want to access an attribute which is set by a role from a recipe, then you just call it like any other node attribute. For example, in the case you presented, assuming the node has the basebox role in its run_list, you would just call:

node['rbenv']['group_users']

The role attributes are merged into the node.

HTH

于 2012-12-05T18:53:36.107 に答える