Reputation: 11017
Environments are great for overriding default behavior and databags are excellent for abstracting data out of cookbooks and making them as generic as possible.
I have an environment json file per phase of development: dev
, qa
, staging
, and I have data bags that I may change based on environment. It seems redundant to me to define these things in more than one directory, especially because I am using chef in local mode
.
Is there a way to define custom properties in the chef environment json file? If so: how can I access them in the recipes?
note: I am already familiar with the override_attributes
property of the environment json. I am wondering about custom json, how to access it, or possibly a better solution?
For Example
{
"name": "dev",
"default_attributes": {},
"json_class": "Chef::Environment",
"my_custom_object" : {"key1":"value1", ...}
"chef_type": "environment"
}
Upvotes: 0
Views: 199
Reputation: 54267
No, you cannot do that. The schema on Chef objects is small (i.e. just which top-level keys are allowed) but fixed. The only places you attach arbitrary data to an environment are as node attributes or (technically but probably don't do this) as encoded data in the description string. That said, node attributes do what you are describing so I'm not entirely sure why you think those aren't the solution (as my other, deleted answer mentioned). I've you've got questions on how to use node attributes I would ask that question instead or ask on Slack :)
Upvotes: 1