summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith84@gmail.com>2020-07-13 09:42:52 -0700
committerTim Smith <tsmith84@gmail.com>2020-07-27 11:03:07 -0700
commit61ba4f6432593f4f594eb38526503b19d66a6ba3 (patch)
tree85b60ff630872f6217d65b5b1be065cb84f7a8b3
parent20052aba8982b37ea20fd128d7dd52c5527d2d79 (diff)
downloadchef-61ba4f6432593f4f594eb38526503b19d66a6ba3.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>
-rw-r--r--lib/chef/resource/hostname.rb29
1 files changed, 14 insertions, 15 deletions
diff --git a/lib/chef/resource/hostname.rb b/lib/chef/resource/hostname.rb
index f096b0e881..dcf7354446 100644
--- a/lib/chef/resource/hostname.rb
+++ b/lib/chef/resource/hostname.rb
@@ -231,27 +231,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