Skip to content

Commit

Permalink
Modify /etc/hosts for RedHat when setting hostname
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellh committed Jan 29, 2011
1 parent 94b5074 commit 60ef9e4
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions lib/vagrant/systems/redhat.rb
Expand Up @@ -26,15 +26,14 @@ def enable_host_only_network(net_options)

def change_host_name(name)
vm.ssh.execute do |ssh|
host_name_already_set = ssh.test?("sudo hostname | grep '#{name}'")
ssh.exec!("sudo sed -i 's/\\(HOSTNAME=\\).*/\\1#{name}/' /etc/sysconfig/network") unless host_name_already_set
ssh.exec!("sudo hostname #{name}") unless host_name_already_set
# Only do this if the hostname is not already set
if !ssh.test?("sudo hostname | grep '#{name}'")
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



0 comments on commit 60ef9e4

Please sign in to comment.