Setting hostname on Debian (not Ubuntu) should now work [closes GH-307]

This commit is contained in:
Mitchell Hashimoto 2011-02-28 23:38:30 -08:00
parent 8792ed8b49
commit 2cfa79ac6d
6 changed files with 27 additions and 3 deletions

View File

@ -3,6 +3,7 @@
- Fix issue with unknown terminal type output for sudo commands. - Fix issue with unknown terminal type output for sudo commands.
- Forwarded port protocol can now be set as UDP. [GH-311] - Forwarded port protocol can now be set as UDP. [GH-311]
- Chef server file cache path and file backup path can be configured. [GH-310] - Chef server file cache path and file backup path can be configured. [GH-310]
- Setting hostname should work on Debian now. [GH-307]
## 0.7.2 (February 8, 2011) ## 0.7.2 (February 8, 2011)

View File

@ -8,3 +8,4 @@ require 'vagrant/systems/solaris'
require 'vagrant/systems/debian' require 'vagrant/systems/debian'
require 'vagrant/systems/gentoo' require 'vagrant/systems/gentoo'
require 'vagrant/systems/redhat' require 'vagrant/systems/redhat'
require 'vagrant/systems/ubuntu'

View File

@ -25,9 +25,9 @@ module Vagrant
def change_host_name(name) def change_host_name(name)
vm.ssh.execute do |ssh| vm.ssh.execute do |ssh|
if !ssh.test?("sudo hostname | grep '#{name}'") if !ssh.test?("sudo hostname | grep '#{name}'")
ssh.exec!("sudo sed -i 's/.*$/#{name}/' /etc/hostname")
ssh.exec!("sudo sed -i 's@^\\(127[.]0[.]1[.]1[[:space:]]\\+\\)@\\1#{name} #{name.split('.')[0]} @' /etc/hosts") ssh.exec!("sudo sed -i 's@^\\(127[.]0[.]1[.]1[[:space:]]\\+\\)@\\1#{name} #{name.split('.')[0]} @' /etc/hosts")
ssh.exec!("sudo service hostname start") ssh.exec!("sudo sed -i 's/.*$/#{name}/' /etc/hostname")
ssh.exec!("sudo hostname -F /etc/hostname")
end end
end end
end end

View File

@ -6,7 +6,11 @@ module Vagrant
class Linux < Base class Linux < Base
def distro_dispatch def distro_dispatch
vm.ssh.execute do |ssh| vm.ssh.execute do |ssh|
return :debian if ssh.test?("cat /etc/debian_version") if ssh.test?("cat /etc/debian_version")
return :debian if ssh.test?("cat /proc/version | grep 'Debian'")
return :ubuntu if ssh.test?("cat /proc/version | grep 'Ubuntu'")
end
return :gentoo if ssh.test?("cat /etc/gentoo-release") return :gentoo if ssh.test?("cat /etc/gentoo-release")
return :redhat if ssh.test?("cat /etc/redhat-release") return :redhat if ssh.test?("cat /etc/redhat-release")
end end

View File

@ -0,0 +1,17 @@
require 'vagrant/systems/debian'
module Vagrant
module Systems
class Ubuntu < Debian
def change_host_name(name)
vm.ssh.execute do |ssh|
if !ssh.test?("sudo hostname | grep '#{name}'")
ssh.exec!("sudo sed -i 's/.*$/#{name}/' /etc/hostname")
ssh.exec!("sudo sed -i 's@^\\(127[.]0[.]1[.]1[[:space:]]\\+\\)@\\1#{name} #{name.split('.')[0]} @' /etc/hosts")
ssh.exec!("sudo service hostname start")
end
end
end
end
end
end

View File

@ -59,6 +59,7 @@ module Vagrant
# Hard-coded internal systems # Hard-coded internal systems
mapping = { mapping = {
:debian => Systems::Debian, :debian => Systems::Debian,
:ubuntu => Systems::Ubuntu,
:freebsd => Systems::FreeBSD, :freebsd => Systems::FreeBSD,
:gentoo => Systems::Gentoo, :gentoo => Systems::Gentoo,
:redhat => Systems::Redhat, :redhat => Systems::Redhat,