Skip to content

Commit

Permalink
Merge pull request #9 from vStone/feature/hostmanager-as-provisioner
Browse files Browse the repository at this point in the history
Use hostmanager as provisioner
  • Loading branch information
smdahlen committed May 2, 2013
2 parents 36acc16 + cae5f6b commit 8adc104
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion lib/vagrant-hostmanager/hosts_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def generate(env, provider)
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
Expand Down
7 changes: 7 additions & 0 deletions lib/vagrant-hostmanager/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ class Plugin < Vagrant.plugin('2')
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
Expand All @@ -22,6 +24,11 @@ class Plugin < Vagrant.plugin('2')
hook.append(Action::UpdateHostsFile)
end

provisioner(:hostmanager) do
require_relative 'provisioner'
Provisioner
end

command(:hostmanager) do
require_relative 'command'
Command
Expand Down
12 changes: 12 additions & 0 deletions lib/vagrant-hostmanager/provisioner.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 8adc104

Please sign in to comment.