Skip to content

Commit

Permalink
Setting hostname on Debian (not Ubuntu) should now work [closes hashi…
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellh committed Mar 1, 2011
1 parent 8792ed8 commit 2cfa79a
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -3,6 +3,7 @@
- Fix issue with unknown terminal type output for sudo commands.
- 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]
- Setting hostname should work on Debian now. [GH-307]

## 0.7.2 (February 8, 2011)

Expand Down
1 change: 1 addition & 0 deletions lib/vagrant/systems.rb
Expand Up @@ -8,3 +8,4 @@
require 'vagrant/systems/debian'
require 'vagrant/systems/gentoo'
require 'vagrant/systems/redhat'
require 'vagrant/systems/ubuntu'
4 changes: 2 additions & 2 deletions lib/vagrant/systems/debian.rb
Expand Up @@ -25,9 +25,9 @@ def enable_host_only_network(net_options)
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")
ssh.exec!("sudo sed -i 's/.*$/#{name}/' /etc/hostname")
ssh.exec!("sudo hostname -F /etc/hostname")
end
end
end
Expand Down
6 changes: 5 additions & 1 deletion lib/vagrant/systems/linux.rb
Expand Up @@ -6,7 +6,11 @@ module Systems
class Linux < Base
def distro_dispatch
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 :redhat if ssh.test?("cat /etc/redhat-release")
end
Expand Down
17 changes: 17 additions & 0 deletions lib/vagrant/systems/ubuntu.rb
@@ -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
1 change: 1 addition & 0 deletions lib/vagrant/vm.rb
Expand Up @@ -59,6 +59,7 @@ def load_system!(system=nil)
# Hard-coded internal systems
mapping = {
:debian => Systems::Debian,
:ubuntu => Systems::Ubuntu,
:freebsd => Systems::FreeBSD,
:gentoo => Systems::Gentoo,
:redhat => Systems::Redhat,
Expand Down

0 comments on commit 2cfa79a

Please sign in to comment.