Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to get current environment in the attribute files?

Tags:

chef-infra

I would like to do something like this:

attributes/default.rb

if node[:chef_environment] == 'dev'
   include_attribute "mbev::dev"
else
   include_attribute "mbdev::production"
end

But it appears that 'node' is equal the name of the current node.

like image 491
mbdev Avatar asked Dec 26 '22 18:12

mbdev


2 Answers

Try node.chef_environment ? It's a function which returns the value rather than an attribute.

like image 187
Iain_b Avatar answered Apr 22 '23 15:04

Iain_b


Inside an attribute file, I think you want to use just chef_environment, according to this post in the Chef Mailing List, and independently confirmed by me.

Your attribute file should then look like this:

if chef_environment == 'dev'
    include_attribute "mbev::dev"
else
    include_attribute "mbdev::production"
end

node.chef_environment will work in recipes.

like image 23
vliao Avatar answered Apr 22 '23 15:04

vliao