MisterStrickland
MisterStrickland

Reputation: 1007

Chef: set an environment variable to an attribute

I saw some answers to similar questions, such as how to set an attribute to an environment variable, or how to set an environment variable in the whole system. But that's not what I'm looking for here.

I understand that the variables will only be available within the context of the cookbook and that is fine.

All I want is to define an attribute, such as:

default['mycookbook']['myvar'] = '3'

and then an environment variable in my recipe, like:

ENV['MY_VAR'] = default['mycookbook']['myvar']

and have $MY_VAR available to be used within the recipe.

Any thoughts?

Upvotes: 0

Views: 2469

Answers (2)

MisterStrickland
MisterStrickland

Reputation: 1007

I found the correct syntax to do it.

For the example given in the question:

ENV['MY_VAR'] = default['mycookbook']['myvar']

Upvotes: 0

Mrigesh Priyadarshi
Mrigesh Priyadarshi

Reputation: 948

As far as the information given in question is concerned, it should work like that by changing default with node.

Define an attribute file , such as:

default['mycookbook']['myvar'] = '3'

And then an environment variable in the recipe, should be like:

# not "default['mycookbook']"['myvar']
ENV['MY_VAR'] = node['mycookbook']['myvar']

Upvotes: 3

Related Questions