guests/ubuntu: Use debians change_host_name functionality

This commit is contained in:
Seth Vargo 2016-07-13 10:02:41 -06:00
parent 7f1947fec2
commit 1e0d7bb652
No known key found for this signature in database
GPG Key ID: 905A90C2949E8787
2 changed files with 0 additions and 57 deletions

View File

@ -1,52 +0,0 @@
module VagrantPlugins
module GuestUbuntu
module Cap
class ChangeHostName
def self.change_host_name(machine, name)
comm = machine.communicate
if !comm.test("hostname -f | grep '^#{name}$'", sudo: false)
basename = name.split(".", 2)[0]
comm.sudo <<-EOH.gsub(/^ {14}/, '')
# Set the hostname
echo '#{basename}' > /etc/hostname
hostname -F /etc/hostname
if command -v hostnamectl; then
hostnamectl set-hostname '#{basename}'
fi
# Remove comments and blank lines from /etc/hosts
sed -i'' -e 's/#.*$//' -e '/^$/d' /etc/hosts
# Prepend ourselves to /etc/hosts
grep -w '#{name}' /etc/hosts || {
sed -i'' '1i 127.0.0.1\\t#{name}\\t#{basename}' /etc/hosts
}
# Update mailname
echo '#{name}' > /etc/mailname
# Restart networking and force new DHCP
if [ test -f /etc/init.d/hostname ]; then
/etc/init.d/hostname start || true
fi
if [ test -f /etc/init.d/hostname.sh ]; then
/etc/init.d/hostname.sh start || true
fi
if [ test -f /etc/init.d/networking ]; then
/etc/init.d/networking force-reload
fi
if [ test -f /etc/init.d/network-manager ]; then
/etc/init.d/network-manager force-reload
fi
EOH
end
end
end
end
end
end

View File

@ -10,11 +10,6 @@ module VagrantPlugins
require_relative "guest"
Guest
end
guest_capability(:ubuntu, :change_host_name) do
require_relative "cap/change_host_name"
Cap::ChangeHostName
end
end
end
end