diff options
author | Tim Smith <tsmith84@gmail.com> | 2020-07-13 09:42:52 -0700 |
---|---|---|
committer | Tim Smith <tsmith84@gmail.com> | 2020-08-17 22:30:14 -0700 |
commit | da832b42084605db226e7c63c50f3fde3f0e6ae7 (patch) | |
tree | 973a00210424f48d4103d5796efe00b90eda6a54 /lib | |
parent | 2654610c31bc193b0f560b38a617e5a945abe0bf (diff) | |
download | chef-da832b42084605db226e7c63c50f3fde3f0e6ae7.tar.gz |
Use powershell_out vs. powershell_script in hostname
This improves the log output and probably speeds up the run since we're
not writing out a temporary script file anymore and then executing it. I
also removed some delcare_resource uses since we enabled unified_mode
for this resource. There's a ton more to remove here.
Signed-off-by: Tim Smith <tsmith@chef.io>
Diffstat (limited to 'lib')
-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 |