diff options
author | Thom May <thom@may.lt> | 2018-03-21 16:49:46 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-21 16:49:46 +0000 |
commit | f52b31f01cd4d11e503aa73aa614d5ccbb00b8f7 (patch) | |
tree | cc86e8b9e91a6317084f29af488733a28f373ea8 /lib/chef/client.rb | |
parent | 26a5e48aa7f447beaee016b0b54ee2076c308dda (diff) | |
parent | 38f11a01425445c161f1dfd2c17ceacbaabf6341 (diff) | |
download | chef-f52b31f01cd4d11e503aa73aa614d5ccbb00b8f7.tar.gz |
Merge pull request #7016 from chef/tm/chef_guid
Save the node's UUID as an attribute
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 b7ea92b506..7218c3bb49 100644 --- a/lib/chef/client.rb +++ b/lib/chef/client.rb @@ -259,6 +259,8 @@ class Chef enforce_path_sanity run_ohai + generate_guid + register unless Chef::Config[:solo_legacy_mode] register_data_collector_reporter @@ -997,6 +999,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 |