From f058b3025f08cca3089465230c45cffd625d99c6 Mon Sep 17 00:00:00 2001 From: Jan Vansteenkiste Date: Thu, 2 May 2013 08:02:58 +0200 Subject: [PATCH 1/2] Fix small scoping issue. @logger is not available from the provisioner --- lib/vagrant-hostmanager/hosts_file.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vagrant-hostmanager/hosts_file.rb b/lib/vagrant-hostmanager/hosts_file.rb index 99c1ca1..e7b4ce2 100644 --- a/lib/vagrant-hostmanager/hosts_file.rb +++ b/lib/vagrant-hostmanager/hosts_file.rb @@ -32,7 +32,7 @@ module VagrantPlugins host = machine.config.vm.hostname || name ip = get_ip_address.call(machine) host_aliases = machine.config.hostmanager.aliases.join("\s").chomp - @logger.info "Adding /etc/hosts entry: #{ip} #{host} #{host_aliases}" + machine.env.ui.info "Adding /etc/hosts entry: #{ip} #{host} #{host_aliases}" file << "#{ip}\t#{host}\s#{host_aliases}\n" end end From cae5f6be7dc6d5da9b3d9163db3425372d711b71 Mon Sep 17 00:00:00 2001 From: Jan Vansteenkiste Date: Thu, 2 May 2013 08:36:40 +0200 Subject: [PATCH 2/2] Add Hostmanager as a provisioner. --- README.md | 11 +++++++++++ lib/vagrant-hostmanager/plugin.rb | 7 +++++++ lib/vagrant-hostmanager/provisioner.rb | 12 ++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 lib/vagrant-hostmanager/provisioner.rb diff --git a/README.md b/README.md index 62f487f..16ae137 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,17 @@ Vagrant.configure("2") do |config| end ``` +As a last option, you can also choose hostmanager as a provisioner. +This allows you to use the provisioning order to ensure that hostmanager +runs before or after provisioning. The provisioner will collect hosts from +boxes with the same provider as the running box. + +Use: + +```ruby +config.vm.provision :hostmanager +``` + Contribute ---------- Contributions are welcome. diff --git a/lib/vagrant-hostmanager/plugin.rb b/lib/vagrant-hostmanager/plugin.rb index c7bd9ca..f73ce6e 100644 --- a/lib/vagrant-hostmanager/plugin.rb +++ b/lib/vagrant-hostmanager/plugin.rb @@ -7,6 +7,8 @@ module VagrantPlugins description <<-DESC This plugin manages the /etc/hosts file for guest machines. An entry is created for each active machine using the hostname attribute. + + You can also use the hostmanager provisioner to update the hosts file. DESC config(:hostmanager) do @@ -22,6 +24,11 @@ module VagrantPlugins hook.append(Action::UpdateHostsFile) end + provisioner(:hostmanager) do + require_relative 'provisioner' + Provisioner + end + command(:hostmanager) do require_relative 'command' Command diff --git a/lib/vagrant-hostmanager/provisioner.rb b/lib/vagrant-hostmanager/provisioner.rb new file mode 100644 index 0000000..65d43db --- /dev/null +++ b/lib/vagrant-hostmanager/provisioner.rb @@ -0,0 +1,12 @@ +module VagrantPlugins + module HostManager + class Provisioner < Vagrant.plugin('2', :provisioner) + include HostsFile + + def provision + generate(@machine.env, @machine.box.provider.to_sym) + update(@machine) + end + end + end +end