Sha256: 786622feb57726c1bd4b2c26eed95a89e114d572d269879ee06cf4884113c94e

Contents?: true

Size: 725 Bytes

Versions: 1

Compression:

Stored size: 725 Bytes

Contents

# Provide a base class for syncing hosts entries on Windows systems.
class VagrantHosts::Cap::SyncHosts::Windows < VagrantHosts::Cap::SyncHosts::Base

  def update_hosts
    host_entries = []
    all_hosts(@config).each do |(address, aliases)|
      aliases.each do |name|
        host_entries << "#{address} #{name}"
      end
    end

    script = []
    script << '$HostsLocation = "$env:windir\\System32\\drivers\\etc\\hosts";'

    host_entries.each do |entry|
      script << "\$HostEntry = \"#{entry}\""
      script << "if (!((gc \$HostsLocation) -contains $HostEntry)) { Add-Content -Path $HostsLocation -Value $HostEntry; }"
    end

    @machine.communicate.sudo(script.join("\r\n"), :elevated => true)
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vagrant-hosts-2.2.2 lib/vagrant-hosts/cap/sync_hosts/windows.rb