Method: Beaker::HostPrebuiltSteps#set_etc_hosts

Defined in:
lib/beaker/host_prebuilt_steps.rb

#set_etc_hosts(host, etc_hosts) ⇒ Object

Append the provided string to the /etc/hosts file of the provided host

Parameters:

  • host (Host)

    the host to act upon

  • etc_hosts (String)

    The string to append to the /etc/hosts file



208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# File 'lib/beaker/host_prebuilt_steps.rb', line 208

def set_etc_hosts(host, etc_hosts)
  if host['platform'].include?('freebsd')
    host.echo_to_file(etc_hosts, '/etc/hosts')
  elsif ((host['platform'].include?('windows')) and not host.is_cygwin?)
    host.exec(Command.new("echo '#{etc_hosts}' >> C:\\Windows\\System32\\drivers\\etc\\hosts"))
  else
    host.exec(Command.new("echo '#{etc_hosts}' >> /etc/hosts"))
  end
  # AIX must be configured to prefer local DNS over external
  return unless host['platform'].include?('aix')

  aix_netsvc = '/etc/netsvc.conf'
  aix_local_resolv = 'hosts = local, bind'
  return if host.exec(Command.new("grep '#{aix_local_resolv}' #{aix_netsvc}"), :accept_all_exit_codes => true).exit_code == 0

  host.exec(Command.new("echo '#{aix_local_resolv}' >> #{aix_netsvc}"))
end