class Chef::Resource::Hostname
Sets the hostname and updates /etc/hosts on *nix systems @since 14.0.0
Constants
- WINDOWS_EC2_CONFIG
Public Instance Methods
Source
# File lib/chef/resource/hostname.rb, line 101 def append_replacing_matching_lines(path, regex, string) text = IO.read(path).split("\n") text.reject! { |s| s =~ regex } text += [ string ] file path do content text.join("\n") + "\n" owner "root" group node["root_group"] mode "0644" not_if { IO.read(path).split("\n").include?(string) } end end
Source
# File lib/chef/resource/hostname.rb, line 132 def is_domain_joined? powershell_exec!("(Get-CIMInstance -Class Win32_ComputerSystem).PartofDomain").result end
Source
# File lib/chef/resource/hostname.rb, line 117 def updated_ec2_config_xml begin require "rexml/document" unless defined?(REXML::Document) 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" end rescue return "" end config.to_s end
read in the xml file used by Ec2ConfigService and update the Ec2SetComputerName setting to disable updating the computer name so we don’t revert our change on reboot @return [String]