fix hostname change on pld

This commit is contained in:
Elan Ruusamäe 2013-11-27 09:35:18 +02:00
parent db9c8dd6b3
commit 2416149aa3
1 changed files with 20 additions and 0 deletions

View File

@ -0,0 +1,20 @@
module VagrantPlugins
module GuestPld
module Cap
class ChangeHostName
def self.change_host_name(machine, name)
machine.communicate.tap do |comm|
# Only do this if the hostname is not already set
if !comm.test("sudo hostname | grep --line-regexp '#{name}'")
comm.sudo("sed -i 's/\\(HOSTNAME=\\).*/\\1#{name}/' /etc/sysconfig/network")
comm.sudo("hostname #{name}")
comm.sudo("sed -i 's@^\\(127[.]0[.]0[.]1[[:space:]]\\+\\)@\\1#{name} #{name.split('.')[0]} @' /etc/hosts")
comm.sudo("sed -i 's/\\(DHCP_HOSTNAME=\\).*/\\1\"#{name}\"/' /etc/sysconfig/interfaces/ifcfg-*")
comm.sudo("service network restart")
end
end
end
end
end
end
end