module Landrush::Cap::Linux::CreateDnsmasqConfig
Public Class Methods
create_dnsmasq_config(env, _ip, tld)
click to toggle source
# File lib/landrush/cap/host/linux/create_dnsmasq_config.rb, line 8 def create_dnsmasq_config(env, _ip, tld) @env = env @tld = tld if contents_match? info 'Host dnsmasq config looks good.' else info 'Need to configure dnsmasq on host.' write_config! end end
Private Class Methods
config_dir()
click to toggle source
# File lib/landrush/cap/host/linux/create_dnsmasq_config.rb, line 25 def config_dir @config_dir ||= Pathname('/etc/NetworkManager/dnsmasq.d') if Landrush::Util::Dnsmasq.nm_managed? @config_dir ||= Pathname('/etc/dnsmasq.d') end
config_file()
click to toggle source
# File lib/landrush/cap/host/linux/create_dnsmasq_config.rb, line 37 def config_file config_dir.join("vagrant-landrush-#{@tld}") end
contents_match?()
click to toggle source
# File lib/landrush/cap/host/linux/create_dnsmasq_config.rb, line 41 def contents_match? config_file.exist? && File.read(config_file) == desired_contents end
desired_contents()
click to toggle source
# File lib/landrush/cap/host/linux/create_dnsmasq_config.rb, line 30 def desired_contents <<-EOS.gsub(/^ +/, '') # Generated by landrush, a vagrant plugin server=/#{@tld}/127.0.0.1#10053 EOS end
ensure_config_exists!()
click to toggle source
# File lib/landrush/cap/host/linux/create_dnsmasq_config.rb, line 56 def ensure_config_exists! if contents_match? info 'Host DNS resolver config looks good.' else info 'Need to configure the host.' write_config! end end
info(msg)
click to toggle source
# File lib/landrush/cap/host/linux/create_dnsmasq_config.rb, line 21 def info(msg) @env.ui.info("[landrush] #{msg}") unless @env.nil? end
write_config!()
click to toggle source
# File lib/landrush/cap/host/linux/create_dnsmasq_config.rb, line 45 def write_config! info 'Momentarily using sudo to put the host config in place...' system "sudo mkdir #{config_dir}" unless config_dir.directory? Tempfile.open('vagrant_landrush_host_config') do |f| f.write(desired_contents) f.close system "sudo cp #{f.path} #{config_file}" system "sudo chmod 644 #{config_file}" end end