Using vagrant-hostmanager with centos/7

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
    (ip = /inet (\d+\.\d+\.\d+\.\d+)/.match(result)) && ip[1]

Michael is a polyglot software engineer, committed to reducing complexity in systems and making them more predictable. Working with a variety of languages and tools, he shares his technical expertise to audiences all around the world at user groups and conferences. You can follow @mheap on Twitter

Thoughts on this post

Leave a comment?

Leave a Reply