Class: Hashicorptools::Packer
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Variables
#variables
#amis, #current_ami, #ec2, #internet_gateway_for_vpc, #sort_by_created_at, #vpc_with_name
Class Method Details
.exit_on_failure? ⇒ Boolean
8
9
10
|
# File 'lib/hashicorptools/packer.rb', line 8
def self.exit_on_failure?
true
end
|
Instance Method Details
#boot ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/hashicorptools/packer.rb', line 65
def boot
run_instances_resp = ec2.run_instances({
image_id: current_ami('base-image').image_id,
min_count: 1,
max_count: 1,
instance_type: "t2.micro"
})
ec2.create_tags({
resources: run_instances_resp.instances.collect(&:instance_id),
tags: [ {key: 'Name', value: "packer test boot #{tag_name}"},
{key: 'environment', value: 'packer-development'},
{key: 'temporary', value: 'kill me'}]
})
require 'byebug'
byebug
end
|
#build ⇒ Object
14
15
16
|
# File 'lib/hashicorptools/packer.rb', line 14
def build
_build
end
|
#clean ⇒ Object
42
43
44
|
# File 'lib/hashicorptools/packer.rb', line 42
def clean
clean_amis
end
|
#clean_snapshots ⇒ Object
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/hashicorptools/packer.rb', line 47
def clean_snapshots
snapshots = ec2.describe_snapshots({owner_ids: ['self']}).snapshots
snapshots.each do |snapshot|
match = snapshot.description.match(/Created by CreateImage\(.+\) for (ami-[0-9a-f]+) from vol-.+/)
if match.nil?
puts "Skipping #{snapshot.id} - #{snapshot.description}"
next
end
ami_id = match[1]
unless Aws::EC2::Image.new(ami_id, region: region).exists?
puts "Removing obsolete snapshot #{snapshot.snapshot_id} - #{snapshot.description}"
ec2.delete_snapshot({snapshot_id: snapshot.snapshot_id})
end
end
end
|
#console ⇒ Object
29
30
31
32
|
# File 'lib/hashicorptools/packer.rb', line 29
def console
require 'byebug'
byebug
end
|
#fix ⇒ Object
24
25
26
|
# File 'lib/hashicorptools/packer.rb', line 24
def fix
system "packer fix #{ami_config_path}"
end
|
#list ⇒ Object
35
36
37
38
39
|
# File 'lib/hashicorptools/packer.rb', line 35
def list
amis_in_region(region).each do |ami|
puts ami.image_id
end
end
|
#validate ⇒ Object
19
20
21
|
# File 'lib/hashicorptools/packer.rb', line 19
def validate
system "packer validate #{ami_config_path}"
end
|