Ram
Ram

Reputation: 251

How do we create a dynamic attribute in chef cookbooks

My requirement is create a dynamic attribute in chef cookbooks. I declared an default attribute in my recipe like below.

default['servicename']['arf'] = "1"

Sometimes, this value needs to be changed to 2 in some of the nodes. How do we pass this value to cookbooks in run-time??

Upvotes: 1

Views: 898

Answers (3)

user2066657
user2066657

Reputation: 479

For the rare case, dump it in as a json snippet during invocation.

chef-client -j '<(echo \{\"servicename\":\{\"arf\":\"1\"\}\})' --no-fork  

Upvotes: 0

Ambareesh V
Ambareesh V

Reputation: 86

you can create a json file as below consider example.json

{ "servicename":{ "arf": 2 } }

and pass it during chef-client execution as below chef-client -j example.json

Upvotes: 1

coderanger
coderanger

Reputation: 54211

It depends on if there are patterns in how it is set. The simplest way is probably to make a Chef role with that value in the role's attributes, and then add it to the run list of any relevant node. You can also set it in the node directly via knife node edit or similar, or via a Chef environment if it's something that varies by env.

Upvotes: 1

Related Questions