Modify /etc/hosts for RedHat when setting hostname

This commit is contained in:
Mitchell Hashimoto 2011-01-28 17:34:26 -08:00
parent 94b5074430
commit 60ef9e482b
1 changed files with 6 additions and 7 deletions

View File

@ -26,15 +26,14 @@ module Vagrant
def change_host_name(name) def change_host_name(name)
vm.ssh.execute do |ssh| vm.ssh.execute do |ssh|
host_name_already_set = ssh.test?("sudo hostname | grep '#{name}'") # Only do this if the hostname is not already set
ssh.exec!("sudo sed -i 's/\\(HOSTNAME=\\).*/\\1#{name}/' /etc/sysconfig/network") unless host_name_already_set if !ssh.test?("sudo hostname | grep '#{name}'")
ssh.exec!("sudo hostname #{name}") unless host_name_already_set ssh.exec!("sudo sed -i 's/\\(HOSTNAME=\\).*/\\1#{name}/' /etc/sysconfig/network")
ssh.exec!("sudo hostname #{name}")
ssh.exec!("sudo sed -i 's@^\\(127[.]0[.]0[.]1[[:space:]]\\+\\)@\\1#{name} @' /etc/hosts")
end
end end
end end
end end
end end
end end