Using vagrant-hostmanager with centos/7
25 Oct 2016 in TIL
I've been trying to use vagrant-hostmanager on a project that requires the machines to have public IP addresses. To make this work with vagrant-hostmanager I needed to write a custom resolver and add it to my Vagrantfile (see #63). This resolver is adapted from the issue and updated to use ip addr as ifconfig isn't installed by default
rubyconfig.hostmanager.ip_resolver = proc do |machine|result = ""machine.communicate.execute("ip addr | grep 'dynamic eth1'") do |type, data|result << data if type == :stdoutend(ip = /inet (\d+\.\d+\.\d+\.\d+)/.match(result)) && ip[1]end