Merge pull request #4527 from Asquera/bugfix/4465-host-not-added-to-etc-hosts
Fix #4465 update /etc/hosts on rhel 7 and derivatives (CentOS)
This commit is contained in:
commit
f24af5dda4
|
@ -3,16 +3,7 @@ module VagrantPlugins
|
|||
module Cap
|
||||
class ChangeHostName
|
||||
def self.change_host_name(machine, name)
|
||||
case machine.guest.capability("flavor")
|
||||
when :rhel_7
|
||||
change_host_name_rhel7(machine, name)
|
||||
else
|
||||
new(machine, name).change!
|
||||
end
|
||||
end
|
||||
|
||||
def self.change_host_name_rhel7(machine, name)
|
||||
machine.communicate.sudo("hostnamectl set-hostname #{name}")
|
||||
new(machine, name).change!
|
||||
end
|
||||
|
||||
attr_reader :machine, :new_hostname
|
||||
|
@ -25,11 +16,17 @@ module VagrantPlugins
|
|||
def change!
|
||||
return unless should_change?
|
||||
|
||||
update_sysconfig
|
||||
update_hostname
|
||||
update_etc_hosts
|
||||
update_dhcp_hostnames
|
||||
restart_networking
|
||||
case machine.guest.capability("flavor")
|
||||
when :rhel_7
|
||||
update_hostname_rhel7
|
||||
update_etc_hosts
|
||||
else
|
||||
update_sysconfig
|
||||
update_hostname
|
||||
update_etc_hosts
|
||||
update_dhcp_hostnames
|
||||
restart_networking
|
||||
end
|
||||
end
|
||||
|
||||
def should_change?
|
||||
|
@ -61,6 +58,10 @@ module VagrantPlugins
|
|||
sudo "hostname #{fqdn}"
|
||||
end
|
||||
|
||||
def update_hostname_rhel7
|
||||
sudo "hostnamectl set-hostname #{fqdn}"
|
||||
end
|
||||
|
||||
# /etc/hosts should resemble:
|
||||
# 127.0.0.1 host.fqdn.com host localhost ...
|
||||
def update_etc_hosts
|
||||
|
|
Loading…
Reference in New Issue