From a0ec46a987870c20995958a22bc2fc6d6f915061 Mon Sep 17 00:00:00 2001 From: Bill Maxwell Date: Tue, 28 Jul 2015 12:35:05 -0700 Subject: [PATCH] Added Hostname capability --- Vagrantfile | 1 + vagrant_rancheros_guest_plugin.rb | 37 +++++++++++++++++++++++++------ 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/Vagrantfile b/Vagrantfile index 6b68080..7fe6ae6 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -29,6 +29,7 @@ Vagrant.configure(2) do |config| ip = "172.19.8.#{i+100}" node.vm.network "private_network", ip: ip + node.vm.hostname = hostname # Disabling compression because OS X has an ancient version of rsync installed. # Add -z or remove rsync__args below if you have a newer version of rsync on your machine. diff --git a/vagrant_rancheros_guest_plugin.rb b/vagrant_rancheros_guest_plugin.rb index 23386dd..a8d503f 100644 --- a/vagrant_rancheros_guest_plugin.rb +++ b/vagrant_rancheros_guest_plugin.rb @@ -10,16 +10,23 @@ IPAddr.class_eval do end module VagrantPlugins - module GuestLinux - class Plugin < Vagrant.plugin("2") - guest_capability("linux", "configure_networks") do - Cap::ConfigureNetworks - end - end + module GuestLinux + class Plugin < Vagrant.plugin("2") + guest_capability("linux", "change_host_name") do + Cap::ChangeHostName + end + guest_capability("linux", "configure_networks") do + Cap::ConfigureNetworks + end + end + end +end + +module VagrantPlugins + module GuestLinux module Cap class ConfigureNetworks - def self.configure_networks(machine, networks) machine.communicate.tap do |comm| interfaces = [] @@ -48,3 +55,19 @@ module VagrantPlugins end end end + +module VagrantPlugins + module GuestLinux + module Cap + class ChangeHostName + def self.change_host_name(machine, name) + machine.communicate.tap do |comm| + if !comm.test("sudo hostname --fqdn | grep '#{name}'") + comm.sudo("hostname #{name.split('.')[0]}") + end + end + end + end + end + end +end