<p>Yesterday I asked <a href="https://devops.stackexchange.com/questions/8186/how-to-use-in-chef-different-attributes-values-for-different-nodes">similar question</a> and found this similar question after getting replies in my own post. What people suggested me in my question is editing a node by <code>knife edit</code> and then setting an attribute for that particular node manually. This attribute would be assigned only to this node. Or the other way - you could create a wrapper cookbook that would override attributes of your "base" cookbook. For more details check out answers and comments for my question.</p>

CC BY-SA 4.0
2019-05-22T06:32:42.707Z
2019-05-22T06:32:42.707Z
Learner
<p>I'm fairly new to Chef and have been writing recipes for Kiosks that we use at work.</p>

<p>I've created a role for the Kiosk that contains a set of attributes, however one of these attributes is a unique ID that is different for each Kiosk node.</p>

<p>This ID is provided by our customer who uses the Kiosk, is abritrary, and can't be generated automatically.</p>

<p>What's best practice for setting this value? I'm using Chef Server and was thinking the best place to do it would be at Bootstrap but not entirely sure how. </p>

CC BY-SA 4.0
2018-07-27T09:52:40.337Z
That's quite vague about this id, can it be generated or should it be set to a specific value ?
Tensibai
CC BY-SA 4.0
2018-07-27T13:08:16.940Z
It has to be set as a specific value, that's different for every node.
Caledonia91
CC BY-SA 4.0
2018-07-27T13:20:29.093Z
What I mean is would something like `node.set['attribute']['id'] = node['fqdn'].hash % 9999`(which give a number between 1 and 9999 derived from hostname) works or not
Tensibai
CC BY-SA 4.0
2018-07-27T13:47:36.983Z
Unfortunately not, the ID is basically an ID given to us from a client and it's different on each node. We do not generate it.
Caledonia91
CC BY-SA 4.0
2018-07-27T13:53:16.403Z
then you should [edit] your question to specify that and show an example on how you get that id (or explain it with more details)
Tensibai
CC BY-SA 4.0
2018-07-27T15:38:25.970Z
I will edit the origional post for clarity, but now you know it's an arbritrary number that's different on each node and can't be generated automatically, do you have any useful sugestions?
Caledonia91
CC BY-SA 4.0
2018-07-27T15:46:21.143Z
I don't know how you provision your nodes, but one option is passing the attribute in a json file at bootstrap/first run by passing something like `-j /etc/chef/first-boot.json` for the first run as showcased [in the docs](https://docs.chef.io/ctl_chef_client.html#examples)
Tensibai
CC BY-SA 4.0
2018-07-29T02:01:59.613Z
When you say "client", are you speaking of the user/customer or the application on the kiosk?
Rilindo
CC BY-SA 4.0
2018-07-30T09:00:01.060Z
When I say client I mean our customer/end user, will edit for clarity
Caledonia91
<chef>
Chef - Setting Unique Node Attributes
Caledonia91
# Chef - Setting Unique Node Attributes

(Asked by: username_0 on 2018-07-27)

I'm fairly new to Chef and have been writing recipes for Kiosks that we use at work.

I've created a role for the Kiosk that contains a set of attributes, however one of these attributes is a unique ID that is different for each Kiosk node.

This ID is provided by our customer who uses the Kiosk, is abritrary, and can't be generated automatically.

What's best practice for setting this value? I'm using Chef Server and was thinking the best place to do it would be at Bootstrap but not entirely sure how.

**Tags:** chef

> **Comments:**
> **username_1**: That's quite vague about this id, can it be generated or should it be set to a specific value ?  
> **username_0**: It has to be set as a specific value, that's different for every node.  
> **username_1**: What I mean is would something like `node.set['attribute']['id'] = node['fqdn'].hash % 9999`(which give a number between 1 and 9999 derived from hostname) works or not  
> **username_0**: Unfortunately not, the ID is basically an ID given to us from a client and it's different on each node. We do not generate it.  
> **username_1**: then you should [edit] your question to specify that and show an example on how you get that id (or explain it with more details)  
> **username_0**: I will edit the origional post for clarity, but now you know it's an arbritrary number that's different on each node and can't be generated automatically, do you have any useful sugestions?  
> **username_1**: I don't know how you provision your nodes, but one option is passing the attribute in a json file at bootstrap/first run by passing something like `-j /etc/chef/first-boot.json` for the first run as showcased [in the docs](https://docs.chef.io/ctl_chef_client.html#examples)  
> **username_2**: When you say "client", are you speaking of the user/customer or the application on the kiosk?  
> **username_0**: When I say client I mean our customer/end user, will edit for clarity  

---

## 1 answers

### Answer by username_3 on 2019-05-22. Score: 1

Yesterday I asked [similar question](https://devops.stackexchange.com/questions/8186/how-to-use-in-chef-different-attributes-values-for-different-nodes) and found this similar question after getting replies in my own post. What people suggested me in my question is editing a node by `knife edit` and then setting an attribute for that particular node manually. This attribute would be assigned only to this node. Or the other way - you could create a wrapper cookbook that would override attributes of your "base" cookbook. For more details check out answers and comments for my question.


---

