2013-04-04 06:18:12 +00:00
|
|
|
module VagrantPlugins
|
|
|
|
module GuestDebian
|
|
|
|
module Cap
|
|
|
|
class ChangeHostName
|
|
|
|
def self.change_host_name(machine, name)
|
|
|
|
machine.communicate.tap do |comm|
|
|
|
|
if !comm.test("hostname --fqdn | grep '^#{name}$' || hostname --short | grep '^#{name}$'")
|
|
|
|
comm.sudo("sed -r -i 's/^(127[.]0[.]1[.]1[[:space:]]+).*$/\\1#{name} #{name.split('.')[0]}/' /etc/hosts")
|
|
|
|
comm.sudo("sed -i 's/.*$/#{name.split('.')[0]}/' /etc/hostname")
|
|
|
|
comm.sudo("hostname -F /etc/hostname")
|
|
|
|
comm.sudo("hostname --fqdn > /etc/mailname")
|
2013-07-17 18:39:32 +00:00
|
|
|
comm.sudo("ifdown -a; ifup -a; ifup -a --allow=hotplug")
|
2013-04-04 06:18:12 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|