SetHostname uses new cap system
This commit is contained in:
parent
511522e9ae
commit
61d2f9f96f
|
@ -18,7 +18,7 @@ module Vagrant
|
||||||
hostname = env[:machine].config.vm.hostname
|
hostname = env[:machine].config.vm.hostname
|
||||||
if !hostname.nil?
|
if !hostname.nil?
|
||||||
env[:ui].info I18n.t("vagrant.actions.vm.hostname.setting")
|
env[:ui].info I18n.t("vagrant.actions.vm.hostname.setting")
|
||||||
env[:machine].guest.change_host_name(hostname)
|
env[:machine].guest.capability(:change_host_name, hostname)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
module VagrantPlugins
|
||||||
|
module GuestDebian
|
||||||
|
module Cap
|
||||||
|
class ChangeHostName
|
||||||
|
def self.change_host_name(machine, name)
|
||||||
|
machine.communicate.tap do |comm|
|
||||||
|
if !comm.test("hostname --fqdn | grep '^#{name}$' || hostname --short | grep '^#{name}$'")
|
||||||
|
comm.sudo("sed -r -i 's/^(127[.]0[.]1[.]1[[:space:]]+).*$/\\1#{name} #{name.split('.')[0]}/' /etc/hosts")
|
||||||
|
comm.sudo("sed -i 's/.*$/#{name.split('.')[0]}/' /etc/hostname")
|
||||||
|
comm.sudo("hostname -F /etc/hostname")
|
||||||
|
comm.sudo("hostname --fqdn > /etc/mailname")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,3 +1,6 @@
|
||||||
|
require 'set'
|
||||||
|
require 'tempfile'
|
||||||
|
|
||||||
require "vagrant/util/template_renderer"
|
require "vagrant/util/template_renderer"
|
||||||
|
|
||||||
module VagrantPlugins
|
module VagrantPlugins
|
||||||
|
|
|
@ -1,31 +1,9 @@
|
||||||
require 'set'
|
|
||||||
require 'tempfile'
|
|
||||||
|
|
||||||
require "vagrant"
|
|
||||||
require 'vagrant/util/template_renderer'
|
|
||||||
|
|
||||||
require Vagrant.source_root.join("plugins/guests/linux/guest")
|
|
||||||
|
|
||||||
module VagrantPlugins
|
module VagrantPlugins
|
||||||
module GuestDebian
|
module GuestDebian
|
||||||
class Guest < VagrantPlugins::GuestLinux::Guest
|
class Guest < Vagrant.plugin("2", :guest)
|
||||||
# Make the TemplateRenderer top-level
|
|
||||||
include Vagrant::Util
|
|
||||||
|
|
||||||
def detect?(machine)
|
def detect?(machine)
|
||||||
machine.communicate.test("cat /proc/version | grep 'Debian'")
|
machine.communicate.test("cat /proc/version | grep 'Debian'")
|
||||||
end
|
end
|
||||||
|
|
||||||
def change_host_name(name)
|
|
||||||
vm.communicate.tap do |comm|
|
|
||||||
if !comm.test("hostname --fqdn | grep '^#{name}$' || hostname --short | grep '^#{name}$'")
|
|
||||||
comm.sudo("sed -r -i 's/^(127[.]0[.]1[.]1[[:space:]]+).*$/\\1#{name} #{name.split('.')[0]}/' /etc/hosts")
|
|
||||||
comm.sudo("sed -i 's/.*$/#{name.split('.')[0]}/' /etc/hostname")
|
|
||||||
comm.sudo("hostname -F /etc/hostname")
|
|
||||||
comm.sudo("hostname --fqdn > /etc/mailname")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -15,6 +15,11 @@ module VagrantPlugins
|
||||||
require_relative "cap/configure_networks"
|
require_relative "cap/configure_networks"
|
||||||
Cap::ConfigureNetworks
|
Cap::ConfigureNetworks
|
||||||
end
|
end
|
||||||
|
|
||||||
|
guest_capability("debian", "change_host_name") do
|
||||||
|
require_relative "cap/change_host_name"
|
||||||
|
Cap::ChangeHostName
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue