I’m a big user of Chef, but was bummed when I couldn’t find any resolver information in Ohai data. I needed to make some changes to an nginx config to use resolver
, but wanted to use the resolver that’s already on the host (since nginx doesn’t inherit that for dynamic backends). Anyway, after a lot of doc reading that led me nowhere, I dug into the source of resolv.rb, and tried about 100 different things until I found something that worked:
1 2 |
require 'resolv' Resolv::DNS::Config.new.lazy_initialize.nameserver_port |
This will give you an array of all your nameservers in resolv.conf, like:
1 |
[["8.8.8.8", 53], ["8.8.4.4", 53], ["4.2.2.1", 53], ["4.2.2.2", 53]] |
In Chef, you can easily iterate over this and use as needed. If you want just the nameservers (without the ports), then you can use:
1 |
Resolv::DNS::Config.new.lazy_initialize.nameserver_port.map{|n| n[0]} |
I hope that helps!
Leave a Reply