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