Using vagrant-hostmanager with centos/7

This article was published 3 years ago. Due to the rapidly evolving world of technology, some concepts may no longer be applicable.

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

config.hostmanager.ip_resolver = proc do |machine|
    result = ""
    machine.communicate.execute("ip addr | grep 'dynamic eth1'") do |type, data|
        result << data if type == :stdout
    end
    (ip = /inet (\d+\.\d+\.\d+\.\d+)/.match(result)) && ip[1]
end

Thoughts on this post

Leave a comment?