summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith84@gmail.com>2020-07-21 08:50:40 -0700
committerTim Smith <tsmith84@gmail.com>2020-07-27 11:03:07 -0700
commitd2c066b572dbe892c10e50af42595606b75e8a0a (patch)
tree244703ce5c93cc70ee4c37e66ff84c0fab067ffa
parent82fffd509b5c7462f0fb1c5677b601000d47bf91 (diff)
downloadchef-d2c066b572dbe892c10e50af42595606b75e8a0a.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 793006096d..e76ea88e8d 100644
--- a/lib/chef/resource/hostname.rb
+++ b/lib/chef/resource/hostname.rb
@@ -87,8 +87,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"
@@ -223,15 +222,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