No commit activity in last 3 years
No release in over 3 years
Enables Vagrant to connect to vSphere VMs via dynamic domain names based on MAC addresses
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

 Project Readme

Build Status Gem Version

Vagrant vSphere DDNS plugin

This is a PoC Vagrant plugin that enables Vagrant to connect to vSphere VMs via dynamic domain names based on MAC addresses. This trivial plugin enables SSH connection to VMs that do not have guest tools installed.

This plugin does not work out of the box and requires custom DHCP and DNS settings. This configuration is however not implemented in the plugin itself and has to be performed manually in advance.

Requirements

Usage

Plugin can be configured by following settings:

  • ddns.host
    • Hostname that will be used for SSH connections instead of guest IP address
    • Patterns mac0, mac1, ... will be replaced by VMs MAC address
  • ddns.ssh_timeout
    • Defines how long the plugin will wait for successfull DNS resolution (default is 120 seconds)
Vagrant.configure("2") do |config|
  config.vm.box = 'dummy-vsphere-box'
  
  config.ddns.host = "%{mac0}.local"
  config.ddns.ssh_timeout = 120
  
  config.vm.provider :vsphere do |vsphere|
    vsphere.host = 'HOST NAME OF YOUR VSPHERE INSTANCE'
    vsphere.compute_resource_name = 'YOUR COMPUTE RESOURCE'
    vsphere.resource_pool_name = 'YOUR RESOURCE POOL'
    vsphere.template_name = '/PATH/TO/YOUR VM TEMPLATE'
    vsphere.name = 'NEW VM NAME'
    vsphere.user = 'YOUR VMWARE USER'
    vsphere.password = 'YOUR VMWARE PASSWORD'
  end
end

After running vagrant up --provider=vsphere Vagrant will attempt to reach VM using specified domain name (e.g. 005056a44d89.local) and fail if it can not be resolved for 2 minutes.

DHCP and DNS settings

  • Allow dynamic DNS updates in Bind in /etc/bind/named.conf.local
...
include "/etc/bind/ddns.key";

zone ".local" {
    type master;
    forwarders {};
	file "/var/lib/bind/db.local";
    allow-update { key dhcpupdate; };
};
...
...
on commit {
    execute("/etc/dhcp/dns_update.py", 
        "--action", "commit", 
        "--ip", binary-to-ascii(10, 8, ".", leased-address),
        "--mac", binary-to-ascii(16, 8, ":", substring(hardware, 1, 6)),
        "--zone", config-option domain-name,
        "--key_file", "/etc/dhcp/ddns.key"
    );
}
on release {
    execute("/etc/dhcp/dns_update.py",
        "--action", "release", 
        "--ip", binary-to-ascii(10, 8, ".", leased-address),
        "--mac", binary-to-ascii(16, 8, ":", substring(hardware, 1, 6)),
        "--zone", config-option domain-name,
        "--key_file", "/etc/dhcp/ddns.key"
    );
}
on expiry {
    execute("/etc/dhcp/dns_update.py", 
        "--action", "expiry", 
        "--ip", binary-to-ascii(10, 8, ".", leased-address),
        "--mac", binary-to-ascii(16, 8, ":", substring(hardware, 1, 6)),
        "--zone", config-option domain-name,
        "--key_file", "/etc/dhcp/ddns.key"
    );
}
...