vagrant/plugins/guests/suse/cap/change_host_name.rb

20 lines
590 B
Ruby
Raw Normal View History

2013-04-04 19:25:10 +00:00
module VagrantPlugins
module GuestSUSE
2013-04-04 19:25:10 +00:00
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
2014-10-23 17:12:27 +00:00
if !comm.test("sudo hostname | grep '#{name}'")
comm.sudo("echo #{name} > /etc/HOSTNAME")
2013-04-04 19:25:10 +00:00
comm.sudo("hostname #{name}")
2013-04-04 19:25:10 +00:00
comm.sudo("sed -i 's@^\\(127[.]0[.]0[.]1[[:space:]]\\+\\)@\\1#{name} #{name.split('.')[0]} @' /etc/hosts")
end
end
end
end
end
end
end