Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge CentOS DHCP_HOSTNAME fixes #58

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,48 @@

when 'centos', 'redhat', 'amazon', 'scientific'
hostfile = '/etc/sysconfig/network'
ifcfg_file = '/etc/sysconfig/network-scripts/ifcfg-eth0'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should not hardcode iface names


ruby_block "Add Host to #{ifcfg_file}" do
block do
file = Chef::Util::FileEdit.new(ifcfg_file)
file.insert_line_if_no_match(/^DHCP_HOSTNAME/, "DHCP_HOSTNAME=#{fqdn}")
file.write_file
end
not_if { File.readlines(ifcfg_file).grep(/^DHCP_HOSTNAME/).any? }
notifies :reload, 'ohai[reload_hostname]', :immediately
end

ruby_block "Update #{ifcfg_file}" do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be combined with the above block

block do
file = Chef::Util::FileEdit.new(ifcfg_file)
file.search_file_replace_line(/^DHCP_HOSTNAME/, "DHCP_HOSTNAME=#{fqdn}")
file.write_file
end
not_if { File.readlines(ifcfg_file).grep(/^DHCP_HOSTNAME/).any? }
notifies :reload, 'ohai[reload_hostname]', :immediately
end

ruby_block "Add Host to #{hostfile}" do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be combined with the next block

block do
file = Chef::Util::FileEdit.new(hostfile)
file.insert_line_if_no_match(/^HOSTNAME/, "HOSTNAME=#{fqdn}")
file.write_file
end
not_if { File.readlines(hostfile).grep(/^HOSTNAME/).any? }
notifies :reload, 'ohai[reload_hostname]', :immediately
end

ruby_block "Update #{hostfile}" do
block do
file = Chef::Util::FileEdit.new(hostfile)
file.search_file_replace_line('^HOSTNAME', "HOSTNAME=#{fqdn}")
file.search_file_replace_line(/^HOSTNAME/, "HOSTNAME=#{fqdn}")
file.write_file
end
not_if { File.readlines(hostfile).grep(/^HOSTNAME/).any? }
notifies :reload, 'ohai[reload_hostname]', :immediately
end

# this is to persist the correct hostname after machine reboot
sysctl = '/etc/sysctl.conf'
ruby_block "Update #{sysctl}" do
Expand Down