summaryrefslogtreecommitdiff
path: root/lib/chef
diff options
context:
space:
mode:
authorThom May <thom@chef.io>2018-03-09 13:37:18 +0000
committerThom May <thom@chef.io>2018-03-09 13:37:18 +0000
commita09fa9c514539a49edd7115917aa79d4ad49976f (patch)
treed6ed49d3f0758c584d3fe4d4b2bbcc0b609d3417 /lib/chef
parent27de91563e5311cf17fdb53e7542db553787ec2f (diff)
downloadchef-a09fa9c514539a49edd7115917aa79d4ad49976f.tar.gz
RFC 106: expose name and chef_environment as attrstm/chef_environment
We also now set chef_environment the same as policy group when that's appropriate Signed-off-by: Thom May <thom@chef.io>
Diffstat (limited to 'lib/chef')
-rw-r--r--lib/chef/node.rb17
-rw-r--r--lib/chef/policy_builder/policyfile.rb6
2 files changed, 19 insertions, 4 deletions
diff --git a/lib/chef/node.rb b/lib/chef/node.rb
index 7b530e1132..496bfedc15 100644
--- a/lib/chef/node.rb
+++ b/lib/chef/node.rb
@@ -330,6 +330,8 @@ class Chef
Chef::Log.debug("Platform is #{platform} version #{version}")
automatic[:platform] = platform
automatic[:platform_version] = version
+ automatic[:name] = name
+ automatic[:chef_environment] = chef_environment
end
def consume_ohai_data(ohai_data)
@@ -421,6 +423,7 @@ class Chef
apply_expansion_attributes(expansion)
+ automatic_attrs[:chef_environment] = chef_environment
expansion
end
@@ -510,7 +513,16 @@ class Chef
return o if o.kind_of? Chef::Node
node = new
node.name(o["name"])
- node.chef_environment(o["chef_environment"])
+
+ node.policy_name = o["policy_name"] if o.has_key?("policy_name")
+ node.policy_group = o["policy_group"] if o.has_key?("policy_group")
+
+ unless node.policy_group.nil?
+ node.chef_environment(o["policy_group"])
+ else
+ node.chef_environment(o["chef_environment"])
+ end
+
if o.has_key?("attributes")
node.normal_attrs = o["attributes"]
end
@@ -525,9 +537,6 @@ class Chef
o["recipes"].each { |r| node.recipes << r }
end
- node.policy_name = o["policy_name"] if o.has_key?("policy_name")
- node.policy_group = o["policy_group"] if o.has_key?("policy_group")
-
node
end
diff --git a/lib/chef/policy_builder/policyfile.rb b/lib/chef/policy_builder/policyfile.rb
index e1293190f8..d479808b4a 100644
--- a/lib/chef/policy_builder/policyfile.rb
+++ b/lib/chef/policy_builder/policyfile.rb
@@ -164,6 +164,11 @@ class Chef
events.node_load_completed(node, run_list_with_versions_for_display, Chef::Config)
events.run_list_expanded(run_list_expansion_ish)
+ # we must do this after `node.consume_external_attrs`
+ node.automatic_attrs[:policy_name] = node.policy_name
+ node.automatic_attrs[:policy_group] = node.policy_group
+ node.automatic_attrs[:chef_environment] = node.policy_group
+
node
rescue Exception => e
events.node_load_failed(node_name, e, Chef::Config)
@@ -400,6 +405,7 @@ class Chef
node.policy_name = policy_name_to_set
node.policy_group = policy_group_to_set
+ node.chef_environment = policy_group_to_set
Chef::Config[:policy_name] = policy_name_to_set
Chef::Config[:policy_group] = policy_group_to_set