7fd5ceeb05
Add description of custom IP resolver |
||
---|---|---|
lib | ||
locales | ||
test | ||
.gitignore | ||
Gemfile | ||
LICENSE.txt | ||
README.md | ||
Rakefile | ||
vagrant-hostmanager.gemspec |
README.md
Vagrant Host Manager
vagrant-hostmanager
is a Vagrant 1.1+ plugin that manages the /etc/hosts
file on guest machines. Its goal is to enable resolution of multi-machine
environments deployed with a cloud provider where IP addresses are not known
in advance.
Status
The current implementation is a proof-of-concept supporting the larger objective of using Vagrant as a cloud management interface for development and production environments.
The plugin has been tested with Vagrant 1.1.5.
Installation
Install the plugin following the typical Vagrant 1.1 procedure:
$ vagrant plugin install vagrant-hostmanager
Usage
To update the /etc/hosts
file on each active machine, run the following
command:
$ vagrant hostmanager
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.
A machine's IP address is defined by either the static IP for a private
network configuration or by the SSH host configuration. To disable
using the private network IP address, set config.hostmanger.ignore_private_ip
to true.
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.
When using include_offline set to true, only boxes that are up or have a private ip configured will be added to the hosts file. You will receive a warning on skipped boxes.
In addition, the hostmanager.aliases
configuration attribute can be used
to provide aliases for your host names.
Example configuration:
Vagrant.configure("2") do |config|
config.hostmanager.enabled = true
config.hostmanager.ignore_private_ip = false
config.hostmanager.include_offline = true
config.vm.define "example-box" do |node|
node.vm.hostname = "example-box-hostname"
node.vm.network :private_network, ip: "192.168.42.42"
node.hostmanager.aliases = %w(example-box.localdomain example-box-alias)
end
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:
config.vm.provision :hostmanager
Custom IP resolver
You can customize way, how host manager resolves IP address for each machine. This might be handy in case of aws provider, where host name is stored in ssh_info hash of each machine. This causes generation of invalid /etc/hosts file.
Custom IP resolver gives you oportunity to calculate IP address for each machine by yourself. For example:
config.hostmanager.ip_resolver = proc do |vm|
if hostname = (vm.ssh_info && vm.ssh_info[:host])
`host #{hostname}`.split("\n").last[/(\d+\.\d+\.\d+\.\d+)/, 1]
end
end
Contribute
Contributions are welcome.
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request