summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsersut <serdar@opscode.com>2014-06-12 14:40:31 -0700
committersersut <serdar@opscode.com>2014-06-12 14:40:31 -0700
commit4c803261f671fd78bb038620937f20f21be6b093 (patch)
treea216a27c02db03834922e23d7a6fd82e8650e45e
parent690dc96357aba79ef4d4aef4cb26fe48e57a89d2 (diff)
downloadchef-sersut/1460.tar.gz
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.sersut/1460
-rw-r--r--lib/chef/application/client.rb13
1 files changed, 12 insertions, 1 deletions
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