summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2018-03-28 21:59:57 -0700
committerTim Smith <tsmith@chef.io>2018-03-28 21:59:57 -0700
commite042718fe4a1a64026a15977bf4ac43f3bbccbcc (patch)
tree8f90830d84bf3828883b5603eda6ace58c1402c9 /lib
parent55ac0da13539f5a80080809ee9059b676dabc5a8 (diff)
downloadchef-e042718fe4a1a64026a15977bf4ac43f3bbccbcc.tar.gz
Do the bare minimum validation to make sure we don't get a FQDN on windowsvalidate_hostname
Throws out the full regex and instead just makes sure someone doesn't give us a FQDN, which will entirely fail the run and result in a infinite reboot. RuntimeError ------------ hostname[chefnode.example.com] (bft::windows line 1) had an error: RuntimeError: Windows hostnames cannot contain a period. Signed-off-by: Tim Smith <tsmith@chef.io>
Diffstat (limited to 'lib')
-rw-r--r--lib/chef/resource/hostname.rb15
1 files changed, 7 insertions, 8 deletions
diff --git a/lib/chef/resource/hostname.rb b/lib/chef/resource/hostname.rb
index 1c91e412a8..497176f45d 100644
--- a/lib/chef/resource/hostname.rb
+++ b/lib/chef/resource/hostname.rb
@@ -11,8 +11,6 @@ class Chef
introduced "14.0"
property :hostname, String,
- regex: /^([A-Za-z0-9])+([A-Za-z0-9-._])*$/, # http://rubular.com/r/c5xKppWX4i
- validation_message: "Hostnames can contain alphanumeric characters, -, ., and _ ,but must start with an alphanumeric character.",
description: "The hostname if different than the resource's name",
name_property: true
@@ -68,12 +66,12 @@ class Chef
action :set do
description "Sets the node's hostname"
- ohai "reload hostname" do
- plugin "hostname"
- action :nothing
- end
-
if node["platform_family"] != "windows"
+ ohai "reload hostname" do
+ plugin "hostname"
+ action :nothing
+ end
+
# set the hostname via /bin/hostname
declare_resource(:execute, "set hostname to #{new_resource.hostname}") do
command "/bin/hostname #{new_resource.hostname}"
@@ -205,8 +203,9 @@ class Chef
end
else # windows
+ raise "Windows hostnames cannot contain a period." if new_resource.hostname.match?(/./)
- # suppress EC2 config service from setting our hostname
+ # suppress EC2 config service from setting our hostname
if ::File.exist?('C:\Program Files\Amazon\Ec2ConfigService\Settings\config.xml')
xml_contents = updated_ec2_config_xml
if xml_contents.empty?