View difference between Paste ID: 5eJwW0uk and yVyjuuCt
SHOW: | | - or go back to the newest paste.
1-
[104] pry(main)> parsed['Reservations'][0]['Instances'][0]['BlockDeviceMappings']
1+
instance_id = JSON.parse(instance_id_json)
2-
=> [{"DeviceName"=>"/dev/sda",
2+
instance_id['rows'].each do |row|
3-
  "Ebs"=>
3+
   	instances = row['normal']['tags']
4-
   {"Status"=>"attached",
4+
   	instances.each do |instance|
5-
    "DeleteOnTermination"=>true,
5+
   		volume_id_json = `aws ec2 describe-instances --instance-ids #{instance} --output json`
6-
    "VolumeId"=>"vol-44068e41",
6+
   		volume_ids = JSON.parse(volume_id_json)
7-
    "AttachTime"=>"2014-08-01T03:48:51.000Z"}},
7+
   		volume_ids['Reservations'][0]['Instances'][0]['BlockDeviceMappings'].map do |volume_id|
8-
 {"DeviceName"=>"/dev/sdb",
8+
   			volumes = volume_id['Ebs']['VolumeId']
9-
  "Ebs"=>
9+
            volumes.each do |volume|
10-
   {"Status"=>"attached",
10+
               	description="Snapshot of Instance #{instance} created on #{DATE}"
11-
    "DeleteOnTermination"=>true,
11+
   				`aws ec2 create-snapshot --volume-id "#{volume}" --description "#{description}"`
12-
    "VolumeId"=>"vol-36068e33",
12+
   				exitstatus = $?.to_i
13-
    "AttachTime"=>"2014-08-01T03:48:51.000Z"}}]
13+
				if exitstatus != 0
14
					puts "Unable to get node names from Chef"
15
				end
16
			end
17
		end	
18
   	end
19
end
20
21
ebs_snapshot_new.rb:21:in `block (3 levels) in <main>': undefined method `each' for "vol-2662ec23":String (NoMethodError)
22
	from ebs_snapshot_new.rb:19:in `map'
23
	from ebs_snapshot_new.rb:19:in `block (2 levels) in <main>'
24
	from ebs_snapshot_new.rb:16:in `each'
25
	from ebs_snapshot_new.rb:16:in `block in <main>'
26
	from ebs_snapshot_new.rb:14:in `each'
27
	from ebs_snapshot_new.rb:14:in `<main>'