2013-04-04 18:49:26 +00:00
|
|
|
module VagrantPlugins
|
2013-04-04 19:09:40 +00:00
|
|
|
module GuestRedHat
|
2013-04-04 18:49:26 +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
|
2013-04-10 16:33:33 +00:00
|
|
|
if !comm.test("sudo hostname | grep --line-regexp '#{name}'")
|
2013-04-04 18:49:26 +00:00
|
|
|
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")
|
2013-09-24 21:48:10 +00:00
|
|
|
comm.sudo("sed -i 's/\\(DHCP_HOSTNAME=\\).*/\\1\"#{name}\"/' /etc/sysconfig/network-scripts/ifcfg-*")
|
|
|
|
comm.sudo("service network restart")
|
2013-04-04 18:49:26 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|