2013-03-27 19:29:21 +00:00
|
|
|
Vagrant Host Manager
|
|
|
|
====================
|
|
|
|
`vagrant-hostmanager` is a Vagrant 1.1+ plugin that manages the `/etc/hosts`
|
2013-06-20 16:54:20 +00:00
|
|
|
file on guest machines (and optionally the host). Its goal is to enable
|
|
|
|
resolution of multi-machine environments deployed with a cloud provider
|
|
|
|
where IP addresses are not known in advance.
|
2013-03-27 19:29:21 +00:00
|
|
|
|
|
|
|
Installation
|
|
|
|
------------
|
|
|
|
Install the plugin following the typical Vagrant 1.1 procedure:
|
|
|
|
|
2013-04-06 12:59:07 +00:00
|
|
|
$ vagrant plugin install vagrant-hostmanager
|
2013-03-27 19:29:21 +00:00
|
|
|
|
|
|
|
Usage
|
|
|
|
-----
|
2013-04-27 12:10:45 +00:00
|
|
|
To update the `/etc/hosts` file on each active machine, run the following
|
|
|
|
command:
|
2013-04-06 12:59:07 +00:00
|
|
|
|
2013-04-08 17:20:22 +00:00
|
|
|
$ vagrant hostmanager
|
2013-03-27 19:29:21 +00:00
|
|
|
|
2013-04-27 12:10:45 +00:00
|
|
|
The plugin may hook into the `vagrant up` and `vagrant destroy` commands
|
|
|
|
automatically. When a machine is created or destroyed, all active
|
|
|
|
machines with the same provider will have their `/etc/hosts` file updated
|
|
|
|
accordingly. Set the `hostmanager.enabled` attribute to `true` in the
|
|
|
|
Vagrantfile to activate this behavior.
|
|
|
|
|
2013-06-20 16:54:20 +00:00
|
|
|
To update the host's `/etc/hosts` file, set the `hostmanager.manage_host`
|
|
|
|
attribute to `true`.
|
|
|
|
|
2013-03-27 19:29:21 +00:00
|
|
|
A machine's IP address is defined by either the static IP for a private
|
2013-04-08 17:20:22 +00:00
|
|
|
network configuration or by the SSH host configuration. To disable
|
|
|
|
using the private network IP address, set `config.hostmanger.ignore_private_ip`
|
|
|
|
to true.
|
2013-03-27 19:29:21 +00:00
|
|
|
|
|
|
|
A machine's host name is defined by `config.vm.hostname`. If this is not
|
|
|
|
set, it falls back to the symbol defining the machine in the Vagrantfile.
|
|
|
|
|
2013-06-20 16:54:20 +00:00
|
|
|
If the `hostmanager.include_offline` attribute is set to `true`, boxes that are
|
|
|
|
up or have a private ip configured will be added to the hosts file.
|
2013-05-06 06:31:31 +00:00
|
|
|
|
2013-04-17 13:57:53 +00:00
|
|
|
In addition, the `hostmanager.aliases` configuration attribute can be used
|
|
|
|
to provide aliases for your host names.
|
2013-04-17 10:24:45 +00:00
|
|
|
|
|
|
|
Example configuration:
|
|
|
|
|
2013-04-17 13:57:53 +00:00
|
|
|
```ruby
|
|
|
|
Vagrant.configure("2") do |config|
|
2013-04-27 12:10:45 +00:00
|
|
|
config.hostmanager.enabled = true
|
2013-06-20 16:54:20 +00:00
|
|
|
config.hostmanager.manage_host = true
|
2013-04-17 13:57:53 +00:00
|
|
|
config.hostmanager.ignore_private_ip = false
|
2013-05-06 06:31:31 +00:00
|
|
|
config.hostmanager.include_offline = true
|
2013-06-20 16:54:20 +00:00
|
|
|
config.vm.define 'example-box' do |node|
|
|
|
|
node.vm.hostname = 'example-box-hostname'
|
|
|
|
node.vm.network :private_network, ip: '192.168.42.42'
|
2013-04-17 13:57:53 +00:00
|
|
|
node.hostmanager.aliases = %w(example-box.localdomain example-box-alias)
|
2013-04-17 10:24:45 +00:00
|
|
|
end
|
2013-04-17 13:57:53 +00:00
|
|
|
end
|
|
|
|
```
|
2013-04-17 10:24:45 +00:00
|
|
|
|
2013-06-20 16:54:20 +00:00
|
|
|
As a last option, you can use hostmanager as a provisioner.
|
2013-05-02 06:36:40 +00:00
|
|
|
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
|
|
|
|
```
|
|
|
|
|
2013-03-27 19:29:21 +00:00
|
|
|
Contribute
|
|
|
|
----------
|
|
|
|
Contributions are welcome.
|
|
|
|
|
|
|
|
1. Fork it
|
|
|
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
|
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
|
|
4. Push to the branch (`git push origin my-new-feature`)
|
|
|
|
5. Create new Pull Request
|