plugins/guests/debian/cap/change_host_name.rb in vagrant-unbundled-2.2.10.0 vs plugins/guests/debian/cap/change_host_name.rb in vagrant-unbundled-2.2.14.0
- old
+ new
@@ -1,7 +1,8 @@
require "log4r"
require 'vagrant/util/guest_hosts'
+require 'vagrant/util/guest_inspection'
require_relative "../../linux/cap/network_interfaces"
module VagrantPlugins
module GuestDebian
module Cap
@@ -13,10 +14,17 @@
def self.change_host_name(machine, name)
@logger = Log4r::Logger.new("vagrant::guest::debian::changehostname")
comm = machine.communicate
if !comm.test("hostname -f | grep '^#{name}$'", sudo: false)
+ network_with_hostname = machine.config.vm.networks.map {|_, c| c if c[:hostname] }.compact[0]
+ if network_with_hostname
+ replace_host(comm, name, network_with_hostname[:ip])
+ else
+ add_hostname_to_loopback_interface(comm, name)
+ end
+
basename = name.split(".", 2)[0]
comm.sudo <<-EOH.gsub(/^ {14}/, '')
# Set the hostname
echo '#{basename}' > /etc/hostname
@@ -55,16 +63,9 @@
if restart_command
comm.sudo(restart_command)
else
restart_each_interface(machine, @logger)
end
- end
-
- network_with_hostname = machine.config.vm.networks.map {|_, c| c if c[:hostname] }.compact[0]
- if network_with_hostname
- replace_host(comm, name, network_with_hostname[:ip])
- else
- add_hostname_to_loopback_interface(comm, name)
end
end
protected