0

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?

StephenKing
  • 36,187
  • 11
  • 83
  • 112
MisterStrickland
  • 947
  • 1
  • 15
  • 35

2 Answers2

3

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']
0

I found the correct syntax to do it.

For the example given in the question:

ENV['MY_VAR'] = default['mycookbook']['myvar']
StephenKing
  • 36,187
  • 11
  • 83
  • 112
MisterStrickland
  • 947
  • 1
  • 15
  • 35