Created
October 28, 2010 05:27
-
-
Save dje/650700 to your computer and use it in GitHub Desktop.
a chef report to google docs
This file contains hidden or 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
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