class Chef::Resource::Hostname
Sets the hostname and updates /etc/hosts on *nix systems @since 14.0.0
Public Instance Methods
after_created()
click to toggle source
this resource forces itself to run at compile_time
# File lib/chef/resource/hostname.rb, line 240 def after_created if compile_time Array(action).each do |action| run_action(action) end end end
append_replacing_matching_lines(path, regex, string)
click to toggle source
# File lib/chef/resource/hostname.rb, line 34 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
updated_ec2_config_xml()
click to toggle source
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]
# File lib/chef/resource/hostname.rb, line 50 def updated_ec2_config_xml begin require "rexml/document" config_file = 'C:\Program Files\Amazon\Ec2ConfigService\Settings\config.xml' config = REXML::Document.new(::File.read(config_file)) # 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