update /etc/hosts on rhel 7
the previous fix for #4465 assumed that the NetworkManager takes care of updating /etc/hosts with the new hostname, but testing shows it doesn't. This change ensures that the change is always added to /etc/hosts when the name changes.
This commit is contained in:
parent
6747f12951
commit
96b011b39e
|
@ -3,16 +3,7 @@ module VagrantPlugins
|
||||||
module Cap
|
module Cap
|
||||||
class ChangeHostName
|
class ChangeHostName
|
||||||
def self.change_host_name(machine, name)
|
def self.change_host_name(machine, name)
|
||||||
case machine.guest.capability("flavor")
|
new(machine, name).change!
|
||||||
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}")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
attr_reader :machine, :new_hostname
|
attr_reader :machine, :new_hostname
|
||||||
|
@ -25,11 +16,17 @@ module VagrantPlugins
|
||||||
def change!
|
def change!
|
||||||
return unless should_change?
|
return unless should_change?
|
||||||
|
|
||||||
update_sysconfig
|
case machine.guest.capability("flavor")
|
||||||
update_hostname
|
when :rhel_7
|
||||||
update_etc_hosts
|
update_hostname_rhel7
|
||||||
update_dhcp_hostnames
|
update_etc_hosts
|
||||||
restart_networking
|
else
|
||||||
|
update_sysconfig
|
||||||
|
update_hostname
|
||||||
|
update_etc_hosts
|
||||||
|
update_dhcp_hostnames
|
||||||
|
restart_networking
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def should_change?
|
def should_change?
|
||||||
|
@ -61,6 +58,10 @@ module VagrantPlugins
|
||||||
sudo "hostname #{fqdn}"
|
sudo "hostname #{fqdn}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def update_hostname_rhel7
|
||||||
|
sudo "hostnamectl set-hostname #{fqdn}"
|
||||||
|
end
|
||||||
|
|
||||||
# /etc/hosts should resemble:
|
# /etc/hosts should resemble:
|
||||||
# 127.0.0.1 host.fqdn.com host localhost ...
|
# 127.0.0.1 host.fqdn.com host localhost ...
|
||||||
def update_etc_hosts
|
def update_etc_hosts
|
||||||
|
|
Loading…
Reference in New Issue