diff options
author | Thom May <thom@chef.io> | 2018-03-20 18:32:26 +0000 |
---|---|---|
committer | Thom May <thom@chef.io> | 2018-03-21 10:45:52 +0000 |
commit | 38f11a01425445c161f1dfd2c17ceacbaabf6341 (patch) | |
tree | f82f1fda08a5a7e5ba3ab90624a0433377153a06 /lib/chef/client.rb | |
parent | e2eaa3fdcd9a5e2f46d90f799eedcd86cc41eb6a (diff) | |
download | chef-38f11a01425445c161f1dfd2c17ceacbaabf6341.tar.gz |
Save the node's UUID as an attributetm/chef_guid
We generate the UUID as part of the data collector report, but we didn't
make that available to the node or the chef server otherwise.
Signed-off-by: Thom May <thom@chef.io>
Diffstat (limited to 'lib/chef/client.rb')
-rw-r--r-- | lib/chef/client.rb | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/chef/client.rb b/lib/chef/client.rb index 6ff2d78ee6..3efaf6f4cf 100644 --- a/lib/chef/client.rb +++ b/lib/chef/client.rb @@ -256,6 +256,8 @@ class Chef enforce_path_sanity run_ohai + generate_guid + register unless Chef::Config[:solo_legacy_mode] register_data_collector_reporter @@ -994,6 +996,27 @@ class Chef Chef::ReservedNames::Win32::Security.has_admin_privileges? end + # Ensure that we have a GUID for this node + # If we've got the proper configuration, we'll simply set that. + # If we're registed with the data collector, we'll migrate that UUID into our configuration and use that + # Otherwise, we'll create a new GUID and save it + def generate_guid + Chef::Config[:chef_guid] ||= + if File.exists?(Chef::Config[:chef_guid_path]) + File.read(Chef::Config[:chef_guid_path]) + else + uuid = UUIDFetcher.node_uuid + File.open(Chef::Config[:chef_guid_path], "w+") do |fh| + fh.write(uuid) + end + uuid + end + end + + class UUIDFetcher + extend Chef::DataCollector::Messages::Helpers + end + # Register the data collector reporter to send event information to the # data collector server def register_data_collector_reporter |