How to find and use network attributes in template

I need to get some network attributes including the DNS master from resolv.conf and the network address in slash notation as an attribute in a template file. I am using @node[‘fqdn’] and @node[‘domain’] successfully, but I don’t know how to get the other values. It looks like I might need a recipe to find those things. Any suggestions?

Hello @mnichols62

I believe the information is scraped by Ohai, the amount of detail you get depends on what Ohai plugins you have installed (guessing the defaults?) and whether any hints files are required. For example Amazon EC2 instances cannot always be detected so placement of a hints file is used to detect EC2 instances.

To find out what information Ohai retrieves simply go on to your VM or machine with Chef/ChefDK installed and type ohai; you can filter out some of the information retrieved by ohai with find (Windows) or grep (CentOS)

ohai | find /i "dns"
ohai | grep "dns"

Alternatively

ohai cpu
ohai kernel
ohai filesystem
ohai network
...

If the information you want is not available you can write your own Ohai plugin https://docs.chef.io/ohai_custom.html

or run a shell out from a recipe to scrape the information and pass into the template as a variable.