summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsmriti <sgarg@msystechnologies.com>2021-04-01 17:27:53 +0530
committersmriti <sgarg@msystechnologies.com>2021-04-01 19:20:28 +0530
commit1adad1898d3aa1afc3d407009c7874a4086e0fcb (patch)
treeadd5b3207f4e3032727c27d14419d2b8dab742e9
parente06ff54100ca557e639658b0ac1d1084e0784d4a (diff)
downloadchef-smriti/10694_allow_fqdn_hostname_resource.tar.gz
Added new property fqdn and made sure hosts entry includes the samesmriti/10694_allow_fqdn_hostname_resource
Signed-off-by: smriti <sgarg@msystechnologies.com>
-rw-r--r--lib/chef/resource/hostname.rb6
1 files changed, 5 insertions, 1 deletions
diff --git a/lib/chef/resource/hostname.rb b/lib/chef/resource/hostname.rb
index 746ef34a5b..77241581d4 100644
--- a/lib/chef/resource/hostname.rb
+++ b/lib/chef/resource/hostname.rb
@@ -50,6 +50,10 @@ class Chef
description: "An optional property to set the hostname if it differs from the resource block's name.",
name_property: true
+ property :fqdn, String,
+ description: "An optional property to set the fqdn if it differs from the resource block's hostname.",
+ introduced: "17.0"
+
property :ipaddress, String,
description: "The IP address to use when configuring the hosts file.",
default: lazy { node["ipaddress"] }, default_description: "The node's IP address as determined by Ohai."
@@ -115,7 +119,7 @@ class Chef
# make sure node['fqdn'] resolves via /etc/hosts
unless new_resource.ipaddress.nil?
- newline = "#{new_resource.ipaddress} #{new_resource.hostname}"
+ newline = "#{new_resource.ipaddress} #{new_resource.fqdn} #{new_resource.hostname}"
newline << " #{new_resource.aliases.join(" ")}" if new_resource.aliases && !new_resource.aliases.empty?
newline << " #{new_resource.hostname[/[^\.]*/]}"
r = append_replacing_matching_lines("/etc/hosts", /^#{new_resource.ipaddress}\s+|\s+#{new_resource.hostname}\s+/, newline)