I have a chef system where we have multiple environments and have attributes set in evironment JSON.
I'm having trouble accessing these from within cookbook attribute files and recipes.
I have a chef system where we have multiple environments and have attributes set in evironment JSON.
I'm having trouble accessing these from within cookbook attribute files and recipes.
What does your environment file look like? Are you setting default or override attributes? If you're setting default, note that is a fairly low priority level in the attributes chain, so it might be overridden by a recipe, or a role.
The precedence of the attributes is as follows, from low to high:
Above from:
Finally I was able to use environment's attribute in the Chef recipe. Lets say we have an environment like this:
{
"name": "QA",
"description": "QA environment",
"cookbook_versions": {
},
"json_class": "Chef::Environment",
"chef_type": "environment",
"default_attributes": {
"comp_rsyslog": {
"filetag_env": "compqa"
}
},
"override_attributes": {
}
}
And we need to use the filetag_env attribute in the service's template config file to pass the environment attribute.
The way I do in the conf erb file it's like:
$InputFileTag <%= node['comp_rsyslog']['filetag_env'] %>,<%= node['rsyslog']['filetag1'] %>
The <%= node['rsyslog']['filetag1'] %>
is defined in the recipe attribute's file:
default['rsyslog']['filetag1'] = 'comp_service'
The result will be a file in /etc/rsyslog.d/comp_service.conf
with a content like:
$InputFileTag compqa,comp_service.
The correct order is now, as taken from the chef documentation site: