From 1e0d7bb652d5de73a3ee8b2aa1fe3b19bd5269e0 Mon Sep 17 00:00:00 2001 From: Seth Vargo Date: Wed, 13 Jul 2016 10:02:41 -0600 Subject: [PATCH] guests/ubuntu: Use debians change_host_name functionality --- plugins/guests/ubuntu/cap/change_host_name.rb | 52 ------------------- plugins/guests/ubuntu/plugin.rb | 5 -- 2 files changed, 57 deletions(-) delete mode 100644 plugins/guests/ubuntu/cap/change_host_name.rb diff --git a/plugins/guests/ubuntu/cap/change_host_name.rb b/plugins/guests/ubuntu/cap/change_host_name.rb deleted file mode 100644 index ffaec34f4..000000000 --- a/plugins/guests/ubuntu/cap/change_host_name.rb +++ /dev/null @@ -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 diff --git a/plugins/guests/ubuntu/plugin.rb b/plugins/guests/ubuntu/plugin.rb index d83e9ed58..3147bdd8f 100644 --- a/plugins/guests/ubuntu/plugin.rb +++ b/plugins/guests/ubuntu/plugin.rb @@ -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