如何在Chef客户端上设置节点属性? [英] How to set Node Attributes on a Chef Client?

查看:47
本文介绍了如何在Chef客户端上设置节点属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用厨师客户端食谱来配置机器作为厨师客户。创建客户端时如何配置节点属性?

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 ?

我不想执行刀节点编辑。我的目的是在创建此节点时设置一些节点属性,可能是通过向JSON文件中添加一些内容。

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.

更新:

我正在创建数百个节点,这些节点将使用此脚本(查看要点)来引导厨师-客户。脚本中的Node_name对于每个节点都会有所不同。同样,我想为将它们分组在一起的节点设置自定义属性。

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.

例如,我想将属于特定项目的所有节点归为一组。我当时在想将属性 project_id添加到节点。这样我以后可以搜索属于项目的所有节点。这对于部署特别有用-在尝试找出属于特定项目的所有db_master角色/网络服务器角色/ memcached角色时。

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 .

所以我要做的是:脚本(应该在主旨中看到)中应该有一些占位符,可以在其中添加自定义属性(例如project_id或其他内容)到Node。可以吗?

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 ?

推荐答案

以上两种方法都可以,或者您可以在配方中使用

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

Node[attribute_name]

为了保持json功能,您可以利用属性或标签

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

添加属性,在生成的json文件中使用类似的内容。可以在脚本中通过参数或csv / xml输入生成属性名称和值

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"
}

这些属性被创建为普通节点属性,并且将由 node [ chef_client] [ interval]进行访问

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

这有意义吗?

这篇关于如何在Chef客户端上设置节点属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆