From 4c803261f671fd78bb038620937f20f21be6b093 Mon Sep 17 00:00:00 2001 From: sersut Date: Thu, 12 Jun 2014 14:40:31 -0700 Subject: Enable local-mode when a config file is not found and when chef_server_url is not specified in the command line for chef-client. --- lib/chef/application/client.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/chef/application/client.rb b/lib/chef/application/client.rb index e9973a1131..b936741f70 100644 --- a/lib/chef/application/client.rb +++ b/lib/chef/application/client.rb @@ -275,11 +275,22 @@ class Chef::Application::Client < Chef::Application def load_config_file Chef::Config.config_file_jail = config[:config_file_jail] if config[:config_file_jail] if !config.has_key?(:config_file) + # If config_file is not specified in the command line, check to see if the default + # config file exists + default_config_path = Chef::Config.platform_specific_path("/etc/chef/client.rb") + config_fetcher = Chef::ConfigFetcher.new(default_config_path, Chef::Config.config_file_jail) + + # If the default config doesn't exist and if server is not specified in the command line + # options, switch local mode on. + if config_fetcher.config_missing? && config[:chef_server_url].nil? + config[:local_mode] = true + end + if config[:local_mode] require 'chef/knife' config[:config_file] = Chef::Knife.locate_config_file else - config[:config_file] = Chef::Config.platform_specific_path("/etc/chef/client.rb") + config[:config_file] = default_config_path end end super -- cgit v1.2.1