在 vagrant 客户端上管理静态 DNS
The vagrant-hosts plugin provides a hosts provisioner which assembles hosts file content based on explicit information and private_network settings. Dynamic sources of hostname info, such as DHCP or provider-specific SSH info are currently not considered.
These settings are on a per provisioner basis. They configure the individual behaviors of each provisioner instance.
hosts[]exports[address, [aliases]]
entries that are exported by this VM. These exports can be collected
by other VMs using the imports setting. These entries may use special
keys as described in the next section.{}imports[]autoconfiguretrue if hosts is empty, otherwise false.add_localhost_hostnames127.0.1.1truechange_hostnametruesync_hostsfalseThe tuples used by the hosts and exports settings are of the form:
[address, [aliases]]For each component, there are some special keys defined that will be replaced by data determined from the VM.
For address, the following special keys may be used:
@facter_ipaddress: Expands to the IPv4 address assigned to the
default network interface of the guest VM.
@vagrant_private_networks: Expands to create one host entry with the given
aliases for each private network attached to a VM that has an explicitly
configured ip address. This is similar to the autoconfigure setting, but
gives control over which aliases are used.
@vagrant_ssh: Expands to the IP address that vagrant ssh uses to connect
with the VM.
For aliases, the following special keys may be used:
@vagrant_hostnames: Expands to an array of aliases containing:Manually specify addresses:
Vagrant.configure('2') do |config|
config.vm.box = "puppetlabs/ubuntu-14.04-64-nocm"
config.vm.provision :hosts do |provisioner|
# Add a single hostname
provisioner.add_host '10.0.2.2', ['myhost.vagrantup.internal']
# Or a fqdn and a short hostname
provisioner.add_host '10.0.2.3', ['myotherhost.vagrantup.internal', 'myotherhost']
# Or as many aliases as you like!
provisioner.add_host '10.0.2.5', [
'mypuppetmaster.vagrantup.internal',
'puppet.vagrantup.internal',
'mypuppetmaster',
'puppet'
]
end
endAutodetect internal network addresses and autoconfigure hosts:
…Use autodetection with manual entries
…Use exports and special keys to share names among VMs:
…The vagrant-hosts plugin provides two Vagrant commands:
vagrant hosts list: List private_network host info in /etc/hosts formatvagrant hosts puppetize: List private_network host info as Puppet Host resourcesAs of version 1.0.0 or later Vagrant 1.1 is required.
Supported guests:
vagrant plugin install vagrant-hosts暂无开放 Issues,或尚未同步最近议题。