diff options
author | Claire McQuin <mcquin@users.noreply.github.com> | 2015-07-21 10:51:54 -0700 |
---|---|---|
committer | Claire McQuin <mcquin@users.noreply.github.com> | 2015-07-21 10:51:54 -0700 |
commit | 2c4d7c7cf40346ca8236054901c023f35e1300c9 (patch) | |
tree | 523f274bc62e0d9b7aaa2c5af6d3bd69ab03c5a9 /lib | |
parent | c91b3371036de811c9b2ba0e26f287e676dfd96f (diff) | |
parent | 14075fd8ac3dd08e80d0e2da08403afbecf798e0 (diff) | |
download | chef-2c4d7c7cf40346ca8236054901c023f35e1300c9.tar.gz |
Merge pull request #3668 from chef/mcquin/first-boot-chef-environment
Set chef_environment in attributes JSON
Diffstat (limited to 'lib')
-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 |