diff options
author | Claire McQuin <claire@getchef.com> | 2015-07-14 14:56:00 -0700 |
---|---|---|
committer | Claire McQuin <claire@getchef.com> | 2015-07-14 15:18:03 -0700 |
commit | 64e0a1da0826f5befababb5693d8bb5b8de913e9 (patch) | |
tree | b9a85ca8077246f91b6b216f30080e188b27c546 /lib/chef/node.rb | |
parent | 2c98a7b90507b2479ffda8ccd31bd464b1f5bee0 (diff) | |
download | chef-64e0a1da0826f5befababb5693d8bb5b8de913e9.tar.gz |
Set chef_environment in attributes JSON
Diffstat (limited to 'lib/chef/node.rb')
-rw-r--r-- | lib/chef/node.rb | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/chef/node.rb b/lib/chef/node.rb index d5078371c5..22c7d5bd8e 100644 --- a/lib/chef/node.rb +++ b/lib/chef/node.rb @@ -315,6 +315,7 @@ class Chef # Consumes the combined run_list and other attributes in +attrs+ def consume_attributes(attrs) normal_attrs_to_merge = consume_run_list(attrs) + normal_attrs_to_merge = consume_chef_environment(normal_attrs_to_merge) Chef::Log.debug("Applying attributes from json file") self.normal_attrs = Chef::Mixin::DeepMerge.merge(normal_attrs,normal_attrs_to_merge) self.tags # make sure they're defined @@ -347,6 +348,24 @@ class Chef attrs end + # chef_environment when set in -j JSON will take precedence over + # -E ENVIRONMENT. Ideally, IMO, the order of precedence should be (lowest to + # highest): + # config_file + # -j JSON + # -E ENVIRONMENT + # so that users could reuse their JSON and override the chef_environment + # configured within it with -E ENVIRONMENT. Because command line options are + # merged with Chef::Config there is currently no way to distinguish between + # an environment set via config from an environment set via command line. + def consume_chef_environment(attrs) + attrs = attrs ? attrs.dup : {} + if env = attrs.delete("chef_environment") + chef_environment(env) + end + attrs + end + # Clear defaults and overrides, so that any deleted attributes # between runs are still gone. def reset_defaults_and_overrides |