diff options
author | Tim Smith <tsmith@chef.io> | 2021-01-19 20:45:36 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-19 20:45:36 -0800 |
commit | d6713d163998bed9f709c926f9b48026fe19ab61 (patch) | |
tree | f19f99a1497fcac64b0689d2c90def38cceb1d32 | |
parent | 1e33db8ad7888a64a54fce73db76197d78108ea4 (diff) | |
parent | a6ea258d62a99de0319710cf48f488f89bb05994 (diff) | |
download | chef-d6713d163998bed9f709c926f9b48026fe19ab61.tar.gz |
Merge pull request #10899 from chef/client_d
Add support for client.d files in chef-shell
-rw-r--r-- | lib/chef/shell.rb | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/lib/chef/shell.rb b/lib/chef/shell.rb index a425129fa8..5bff9c0292 100644 --- a/lib/chef/shell.rb +++ b/lib/chef/shell.rb @@ -25,6 +25,7 @@ require "pp" unless defined?(PP) require "etc" unless defined?(Etc) require "mixlib/cli" unless defined?(Mixlib::CLI) require "chef-utils/dist" unless defined?(ChefUtils::Dist) +require "chef-config/mixin/dot_d" require_relative "../chef" require_relative "version" @@ -211,6 +212,7 @@ module Shell class Options include Mixlib::CLI + include ChefConfig::Mixin::DotD def self.footer(text = nil) @footer = text if text @@ -341,15 +343,44 @@ module Shell # We have to nuke ARGV to make sure irb's option parser never sees it. # otherwise, IRB complains about command line switches it doesn't recognize. ARGV.clear + + # This code should not exist. + # We should be using Application::Client and then calling load_config_file + # which does all this properly. However this will do for now. config[:config_file] = config_file_for_shell_mode(environment) config_msg = config[:config_file] || "none (standalone session)" puts "loading configuration: #{config_msg}" - Chef::Config.from_file(config[:config_file]) if !config[:config_file].nil? && File.exist?(config[:config_file]) && File.readable?(config[:config_file]) + + # load the config (if we have one) + if !config[:config_file].nil? + if File.exist?(config[:config_file]) && File.readable?(config[:config_file]) + Chef::Config.from_file(config[:config_file]) + end + + # even if we couldn't load that, we need to tell Chef::Config what + # the file was so it sets confdir and d_dir and such properly + Chef::Config[:config_file] = config[:config_file] + + # now attempt to load any relevant dot-dirs + load_dot_d(Chef::Config[:client_d_dir]) if Chef::Config[:client_d_dir] + end + + # finally merge command-line options in Chef::Config.merge!(config) end private + # shamelessly lifted from application.rb + def apply_config(config_content, config_file_path) + Chef::Config.from_string(config_content, config_file_path) + rescue Exception => error + logger.fatal("Configuration error #{error.class}: #{error.message}") + filtered_trace = error.backtrace.grep(/#{Regexp.escape(config_file_path)}/) + filtered_trace.each { |line| logger.fatal(" " + line ) } + raise Chef::Exceptions::ConfigurationError.new("Aborting due to error in '#{config_file_path}': #{error}") + end + def config_file_for_shell_mode(environment) dot_chef_dir = Chef::Util::PathHelper.home(".chef") if config[:config_file] |