diff options
-rw-r--r-- | lib/chef/resource/hostname.rb | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/lib/chef/resource/hostname.rb b/lib/chef/resource/hostname.rb index 7329dd34bf..8c15cf5a2b 100644 --- a/lib/chef/resource/hostname.rb +++ b/lib/chef/resource/hostname.rb @@ -228,27 +228,26 @@ class Chef if xml_contents.empty? Chef::Log.warn('Unable to properly parse and update C:\Program Files\Amazon\Ec2ConfigService\Settings\config.xml contents. Skipping file update.') else - declare_resource(:file, 'C:\Program Files\Amazon\Ec2ConfigService\Settings\config.xml') do + file 'C:\Program Files\Amazon\Ec2ConfigService\Settings\config.xml' do content xml_contents end end end - # update via netdom - declare_resource(:powershell_script, "set hostname") do - code <<-EOH - $sysInfo = Get-WmiObject -Class Win32_ComputerSystem - $sysInfo.Rename("#{new_resource.hostname}") - EOH - notifies :request_reboot, "reboot[setting hostname]" - not_if { Socket.gethostbyname(Socket.gethostname).first == new_resource.hostname } - end + unless Socket.gethostbyname(Socket.gethostname).first == new_resource.hostname + converge_by "set hostname to #{new_resource.hostname}" do + powershell_out! <<~EOH + $sysInfo = Get-WmiObject -Class Win32_ComputerSystem + $sysInfo.Rename("#{new_resource.hostname}") + EOH + end - # reboot because $windows - declare_resource(:reboot, "setting hostname") do - reason "#{Chef::Dist::PRODUCT} updated system hostname" - action :nothing - only_if { new_resource.windows_reboot } + # reboot because $windows + reboot "setting hostname" do + reason "#{Chef::Dist::PRODUCT} updated system hostname" + action :nothing + only_if { new_resource.windows_reboot } + end end end end |