Skip to content

Instantly share code, notes, and snippets.

@macros
Created January 28, 2012 21:54
Show Gist options
  • Save macros/1695881 to your computer and use it in GitHub Desktop.
Save macros/1695881 to your computer and use it in GitHub Desktop.
chef-client --collect_only
diff --git a/chef/lib/chef/application/client.rb b/chef/lib/chef/application/client.rb
index 1c60ffb..706cf83 100644
--- a/chef/lib/chef/application/client.rb
+++ b/chef/lib/chef/application/client.rb
@@ -142,6 +142,12 @@ class Chef::Application::Client < Chef::Application
:proc => lambda {|v| puts "Chef: #{::Chef::VERSION}"},
:exit => 0
+ option :collect_only,
+ :short => "-C",
+ :long => "--collect_only",
+ :description => "Run ohai and update the node object",
+ :boolean => true
+
attr_reader :chef_client_json
def initialize
@@ -223,7 +229,7 @@ class Chef::Application::Client < Chef::Application
puts "Chef version: #{::Chef::VERSION}"
end
- if Chef::Config[:daemonize]
+ if Chef::Config[:daemonize] && !Chef::Config[:collect_only]
Chef::Daemon.daemonize("chef-client")
end
@@ -236,8 +242,11 @@ class Chef::Application::Client < Chef::Application
end
@chef_client = Chef::Client.new(@chef_client_json)
@chef_client_json = nil
-
- @chef_client.run
+ if Chef::Config[:collect_only]
+ @chef_client.run_collect_only
+ else
+ @chef_client.run
+ end
@chef_client = nil
if Chef::Config[:interval]
Chef::Log.debug("Sleeping for #{Chef::Config[:interval]} seconds")
diff --git a/chef/lib/chef/client.rb b/chef/lib/chef/client.rb
index cabc407..d697c25 100644
--- a/chef/lib/chef/client.rb
+++ b/chef/lib/chef/client.rb
@@ -177,6 +177,14 @@ class Chef
true
end
+ def run_collect_only
+ Chef::Log.info("*** Chef #{Chef::VERSION} ***")
+ enforce_path_sanity
+ run_ohai
+ register unless Chef::Config[:solo]
+ build_node
+ save_updated_node
+ end
# Configures the Chef::Cookbook::FileVendor class to fetch file from the
# server or disk as appropriate, creates the run context for this run, and
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment