summaryrefslogtreecommitdiff
path: root/lib/chef/node.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chef/node.rb')
-rw-r--r--lib/chef/node.rb23
1 files changed, 21 insertions, 2 deletions
diff --git a/lib/chef/node.rb b/lib/chef/node.rb
index 9823185ede..d5078371c5 100644
--- a/lib/chef/node.rb
+++ b/lib/chef/node.rb
@@ -77,13 +77,30 @@ class Chef
@run_state = {}
end
+ # after the run_context has been set on the node, go through the cookbook_collection
+ # and setup the node[:cookbooks] attribute so that it is published in the node object
+ def set_cookbook_attribute
+ return unless run_context.cookbook_collection
+ run_context.cookbook_collection.each do |cookbook_name, cookbook|
+ automatic_attrs[:cookbooks][cookbook_name][:version] = cookbook.version
+ end
+ end
+
# Used by DSL
def node
self
end
def chef_server_rest
- @chef_server_rest ||= Chef::REST.new(Chef::Config[:chef_server_url])
+ # for saving node data we use validate_utf8: false which will not
+ # raise an exception on bad utf8 data, but will replace the bad
+ # characters and render valid JSON.
+ @chef_server_rest ||= Chef::REST.new(
+ Chef::Config[:chef_server_url],
+ Chef::Config[:node_name],
+ Chef::Config[:client_key],
+ validate_utf8: false,
+ )
end
# Set the name of this Node, or return the current name.
@@ -244,6 +261,7 @@ class Chef
# saved back to the node and be searchable
def loaded_recipe(cookbook, recipe)
fully_qualified_recipe = "#{cookbook}::#{recipe}"
+
automatic_attrs[:recipes] << fully_qualified_recipe unless Array(self[:recipes]).include?(fully_qualified_recipe)
end
@@ -354,7 +372,8 @@ class Chef
self.tags # make sure they're defined
- automatic_attrs[:recipes] = expansion.recipes
+ automatic_attrs[:recipes] = expansion.recipes.with_fully_qualified_names_and_version_constraints
+ automatic_attrs[:expanded_run_list] = expansion.recipes.with_fully_qualified_names_and_version_constraints
automatic_attrs[:roles] = expansion.roles
apply_expansion_attributes(expansion)