summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith84@gmail.com>2020-07-21 08:50:40 -0700
committerTim Smith <tsmith84@gmail.com>2020-08-17 22:31:04 -0700
commit29ed4ff2c7bbc2098c11a8d93a5ffab4fa1b8a30 (patch)
treeccedd89757f09672ae78fab821f045d4ffed9422
parent654b6404133132b125982f2eae666d794e0a14c7 (diff)
downloadchef-29ed4ff2c7bbc2098c11a8d93a5ffab4fa1b8a30.tar.gz
Use a const for the ec2 config location on windows
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--lib/chef/resource/hostname.rb9
1 files changed, 5 insertions, 4 deletions
diff --git a/lib/chef/resource/hostname.rb b/lib/chef/resource/hostname.rb
index 592951a3b8..a4f694f391 100644
--- a/lib/chef/resource/hostname.rb
+++ b/lib/chef/resource/hostname.rb
@@ -67,8 +67,7 @@ class Chef
def updated_ec2_config_xml
begin
require "rexml/document" unless defined?(REXML::Document)
- config_file = 'C:\Program Files\Amazon\Ec2ConfigService\Settings\config.xml'
- config = REXML::Document.new(::File.read(config_file))
+ config = REXML::Document.new(::File.read(WINDOWS_EC2_CONFIG))
# find an element named State with a sibling element whose value is Ec2SetComputerName
REXML::XPath.each(config, "//Plugin/State[../Name/text() = 'Ec2SetComputerName']") do |element|
element.text = "Disabled"
@@ -220,15 +219,17 @@ class Chef
end
else # windows
+ WINDOWS_EC2_CONFIG = 'C:\Program Files\Amazon\Ec2ConfigService\Settings\config.xml'.freeze
+
raise "Windows hostnames cannot contain a period." if new_resource.hostname.match?(/\./)
# suppress EC2 config service from setting our hostname
- if ::File.exist?('C:\Program Files\Amazon\Ec2ConfigService\Settings\config.xml')
+ if ::File.exist?(WINDOWS_EC2_CONFIG)
xml_contents = updated_ec2_config_xml
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
- file 'C:\Program Files\Amazon\Ec2ConfigService\Settings\config.xml' do
+ file WINDOWS_EC2_CONFIG do
content xml_contents
end
end