Created
February 5, 2010 02:40
-
-
Save schisamo/295436 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'json' | |
require 'chef' | |
hosts = "# Host File generated from Chef Search on #{Time.now}\n" | |
# perform search via knife and loop through results | |
JSON.parse(%x(knife list_nodes)).each do |n| | |
# parse result as Chef::Node..uses the result json_type | |
node = JSON.parse(%x(knife show_node --node=#{n})) | |
# extract ipaddress and fqdn | |
hosts << "#{node.ipaddress}\t\t#{node.hostname}\t\t#{node.fqdn}\n" | |
end | |
# append our localhost info | |
hosts << "127.0.0.1\t\tlocalhost | |
255.255.255.255\t\tbroadcasthost | |
::1\t\t\tlocalhost | |
fe80::1%lo0\t\tlocalhost\n" | |
puts hosts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment