Skip to content

Instantly share code, notes, and snippets.

@botchagalupe
Forked from dje/report.rb
Created December 15, 2010 00:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save botchagalupe/741414 to your computer and use it in GitHub Desktop.
Save botchagalupe/741414 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'chef'
require 'fog'
require 'google_spreadsheet'
Chef::Config.from_file("~/.chef/knife.rb")
ec2 = Fog::AWS::EC2.new(:aws_access_key_id => ENV["AWS_KEY"],
:aws_secret_access_key => ENV["AWS_SECRET"] )
session = GoogleSpreadsheet.login ENV["GOOGLE_EMAIL"], ENV["GOOGLE_PASSWORD"]
sheet = session.create_spreadsheet "Instances #{Time.now.strftime "%Y%m%d"}"
chef_list = Chef::Node.list.keys
ec2_list = ec2.servers.all.map {|s| s.id}
ws = sheet.worksheets.first
ws[1,1] = "Name"
ws[1,2] = "IP Address"
ws[1,3] = "Run List"
relevant = (chef_list & ec2_list)
relevant.each_with_index do |node, i|
i = i + 2
ws[i,1] = node
ws[i,2] = ec2.servers.get(node).ip_address
ws[i,3] = Chef::Node.load(node).run_list.to_s
end
start = relevant.length + 3
ws[start,1] = "Running, not recorded"
ws[start,2] = "Recorded, not running"
(ec2_list - chef_list).each_with_index do |node, i|
i = i + start + 1
ws[i,1] = node
end
(chef_list - ec2_list).each_with_index do |node, i|
i = i + start + 1
ws[i,2] = node
end
ws.save
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment