Last active
December 15, 2015 06:59
-
-
Save DmZ/5220159 to your computer and use it in GitHub Desktop.
Allow override normal attributes passed by command line to chef-solo.
Put to libraries/ folder of your cookbook.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Load attributes from local file | |
# overriding/merging with command line attributes | |
# | |
require 'chef/run_context' | |
class Chef::RunContext | |
alias_method :original_load_attributes, :load_attributes | |
def load_attributes | |
filename = '/etc/chef/attrs.json' | |
begin | |
json_file = open(filename) | |
json = Chef::JSONCompat.from_json(json_file.read) | |
json_file.close unless json_file.closed? | |
Chef::Log.debug("Node #{@node.name} loading attributes from json #{filename}") | |
@node.consume_attributes(json) | |
rescue Exception => error | |
Chef::Log.debug("Skipping #{filename} due to error: " + error.message) | |
end | |
original_load_attributes | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Chef 10.x only for now.
(For Chef 11.x need to override Chef::RunContext::CookbookCompiler.compile_attributes instead)