How to set Node Attributes on a Chef Client?

ぃ、小莉子 提交于 2019-12-20 01:59:13

问题


I'm using the chef-client cookbook to configure a machine as a chef client . How do I configure node attributes when this client is created ?

I do not want to do knife node edit . My aim is to set some node attributes when creating this node, probably by adding something to a JSON file.

UPDATE:

I am creating hundreds of nodes which will use this script (see the gist) to bootstrap chef-clients. Node_name which is in the script will be different for each node. Similarly I want to set a custom attribute to the node that will group them together.

Say for example I want to group all the nodes belonging to a particular project together. I was thinking I will add an attribute "project_id" to the Node. So that I can search later for all nodes belonging to a project. This is especially useful for deployments - while trying to find out all db_master roles / webserver roles / memcached roles belonging to a particular project .

So what I want to do is this : there should be some placeholder in the script (which you saw in the gist) where I can add custom attributes like project_id or whatever to the Node. Is that possible ?


回答1:


Both the above work or you can create them in recipes using something like

Node[attribute_name]

To keep with your json functionality you could leverage attributes or tags

to add attributes use something like this in your json file that you're generating. The attribute name and value can be generated in your script by parameters or csv/xml input

{

    "test_attribute" : "testvalue"
}

In the example you've linked to they are setting attributes under a chef-client hash

"chef_client": {
 "server_url": "http://ec2-23-20-173-176.compute-1.amazonaws.com:4000",
 "interval": "20"
}

Those attributes are created as normal node attributes and would be accessed by node["chef_client"]["interval"] for example.

Does that make sense?




回答2:


Either give the client a role and add attributes there or pass a .json file containing node data using the -j parameter of chef-client.




回答3:


Lets say you want to add the recipe mouse to your node target1.

knife node run_list add target1 "recipe[mouse]"

It should work with all the attributes.



来源:https://stackoverflow.com/questions/13381843/how-to-set-node-attributes-on-a-chef-client

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!