Module: Vagrant::Util::GuestHosts::BSD

Includes:
Unix
Defined in:
lib/vagrant/util/guest_hosts.rb

Overview

BSD specific inspection helpers

Constant Summary

Constants included from Unix

Unix::DEAFAULT_LOOPBACK_CHECK_LIMIT

Instance Method Summary collapse

Methods included from Unix

#add_hostname_to_loopback_interface

Instance Method Details

#replace_host(comm, name, ip) ⇒ Object

Remove any line in /etc/hosts that contains hostname, then add hostname with associated ip

Parameters:

  • (Communicator)
  • full (String)

    hostanme

  • target (String)

    ip


58
59
60
61
62
63
64
# File 'lib/vagrant/util/guest_hosts.rb', line 58

def replace_host(comm, name, ip)
  basename = name.split(".", 2)[0]
  comm.sudo <<-EOH.gsub(/^ {14}/, '')
  sed -i.bak '/#{name}/d' /etc/hosts
  sed -i.bak '1i\\\n#{ip}\t#{name}\t#{basename}\n' /etc/hosts
  EOH
end