Chef : Define an attribute with the value of another attribute

253 Views Asked by At

In my environment file, I have defined an attribute say

['app']['web'] = 'nginx'

and in another environment file

['app']['web'] = 'apache'

My intention is to create a recipe which will run on any environment. Inside the recipe I'm defining one attribute. So while running this recipe in the first environment I want to define node.default['cluster']['nginx']['endpoint'] and in second environment it should be node.default['cluster']['apache']['endpoint']

I used the following

node.default['cluster'][node['app']['web']]['endpoint']

But this is not working. Is there any way I can achieve this ?

2

There are 2 best solutions below

0
On

See https://github.com/poise/poise-derived for a solution. More characters because I have to.

1
On

it is hard to give you a concrete answer since you did not specify the attribute type. the attribute type in conjunction with the attribute precedence will determine whether node['app']['web'] holds non nil value at the chef-client compilation phase