2013-04-04 18:39:58 +00:00
|
|
|
module VagrantPlugins
|
|
|
|
module GuestArch
|
|
|
|
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 '#{name}'")
|
2013-08-10 00:41:18 +00:00
|
|
|
comm.sudo("hostnamectl set-hostname #{name}")
|
2013-04-04 18:39:58 +00:00
|
|
|
comm.sudo("sed -i 's@^\\(127[.]0[.]0[.]1[[:space:]]\\+\\)@\\1#{name} @' /etc/hosts")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|