PackerFiles 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/PackerFiles.gemspec +36 -0
- data/README.md +32 -0
- data/Rakefile +21 -0
- data/bin/pkf +5 -0
- data/lib/PackerFiles/CLI/OS.rb +44 -0
- data/lib/PackerFiles/CLI/Root.rb +41 -0
- data/lib/PackerFiles/Core/Base.rb +23 -0
- data/lib/PackerFiles/Core/CDImage.rb +185 -0
- data/lib/PackerFiles/Core/Disk.rb +135 -0
- data/lib/PackerFiles/Core/Exceptions.rb +65 -0
- data/lib/PackerFiles/Core/Hypervisor.rb +96 -0
- data/lib/PackerFiles/Core/Keyboard.rb +38 -0
- data/lib/PackerFiles/Core/Locale.rb +62 -0
- data/lib/PackerFiles/Core/LogicalVolume.rb +41 -0
- data/lib/PackerFiles/Core/Network.rb +67 -0
- data/lib/PackerFiles/Core/Packages.rb +30 -0
- data/lib/PackerFiles/Core/Partition.rb +41 -0
- data/lib/PackerFiles/Core/TimeZone.rb +45 -0
- data/lib/PackerFiles/Core/User.rb +46 -0
- data/lib/PackerFiles/Core/VolumeGroup.rb +50 -0
- data/lib/PackerFiles/Core/example/CDImage.txt +75 -0
- data/lib/PackerFiles/Core/example/Disk.txt +29 -0
- data/lib/PackerFiles/Core/example/Hypervisor.txt +111 -0
- data/lib/PackerFiles/Core/example/Keyboard.txt +28 -0
- data/lib/PackerFiles/Core/example/Locale.txt +31 -0
- data/lib/PackerFiles/Core/example/Network.txt +68 -0
- data/lib/PackerFiles/Core/example/Packages.txt +22 -0
- data/lib/PackerFiles/Core/example/TimeZone.txt +36 -0
- data/lib/PackerFiles/Core/example/User.txt +48 -0
- data/lib/PackerFiles/OS/Builder.rb +116 -0
- data/lib/PackerFiles/OS/CentOS/CD.rb +81 -0
- data/lib/PackerFiles/OS/CentOS/Kickstart.rb +64 -0
- data/lib/PackerFiles/OS/CentOS/Server.rb +170 -0
- data/lib/PackerFiles/OS/CentOS/Templates/Base_erb.rb +4 -0
- data/lib/PackerFiles/OS/CentOS/Templates/Disk_erb.rb +35 -0
- data/lib/PackerFiles/OS/CentOS/Templates/Keyboard_erb.rb +4 -0
- data/lib/PackerFiles/OS/CentOS/Templates/Locale_erb.rb +4 -0
- data/lib/PackerFiles/OS/CentOS/Templates/Network_erb.rb +17 -0
- data/lib/PackerFiles/OS/CentOS/Templates/Packages_erb.rb +34 -0
- data/lib/PackerFiles/OS/CentOS/Templates/Tail_erb.rb +15 -0
- data/lib/PackerFiles/OS/CentOS/Templates/TimeZone_erb.rb +10 -0
- data/lib/PackerFiles/OS/CentOS/Templates/User_erb.rb +20 -0
- data/lib/PackerFiles/OS/CentOS/Templates/boot_command_erb.rb +16 -0
- data/lib/PackerFiles/OS/CentOS/Templates/command_as_root_erb.rb +1 -0
- data/lib/PackerFiles/OS/CentOS/Templates/disable_root_erb.rb +1 -0
- data/lib/PackerFiles/OS/CentOS/Templates/enable_root_erb.rb +1 -0
- data/lib/PackerFiles/OS/CentOS/Templates/shutdown_command_erb.rb +1 -0
- data/lib/PackerFiles/OS/Debian/Apt.rb +42 -0
- data/lib/PackerFiles/OS/Debian/CD.rb +65 -0
- data/lib/PackerFiles/OS/Debian/Mirrors.rb +73 -0
- data/lib/PackerFiles/OS/Debian/Preseed.rb +64 -0
- data/lib/PackerFiles/OS/Debian/Server.rb +169 -0
- data/lib/PackerFiles/OS/Debian/Templates/Apt_erb.rb +18 -0
- data/lib/PackerFiles/OS/Debian/Templates/Disk_erb.rb +69 -0
- data/lib/PackerFiles/OS/Debian/Templates/Keyboard_erb.rb +5 -0
- data/lib/PackerFiles/OS/Debian/Templates/Locale_erb.rb +7 -0
- data/lib/PackerFiles/OS/Debian/Templates/Mirrors_erb.rb +9 -0
- data/lib/PackerFiles/OS/Debian/Templates/Network_erb.rb +19 -0
- data/lib/PackerFiles/OS/Debian/Templates/Packages_erb.rb +6 -0
- data/lib/PackerFiles/OS/Debian/Templates/TimeZone_erb.rb +6 -0
- data/lib/PackerFiles/OS/Debian/Templates/User_erb.rb +14 -0
- data/lib/PackerFiles/OS/Debian/Templates/boot_command_erb.rb +24 -0
- data/lib/PackerFiles/OS/Debian/Templates/command_as_root_erb.rb +1 -0
- data/lib/PackerFiles/OS/Debian/Templates/disable_root_erb.rb +5 -0
- data/lib/PackerFiles/OS/Debian/Templates/enable_root_erb.rb +1 -0
- data/lib/PackerFiles/OS/Debian/Templates/shutdown_command_erb.rb +1 -0
- data/lib/PackerFiles/OS/Debian/example/Apt.txt +55 -0
- data/lib/PackerFiles/OS/DocGenerator.rb +51 -0
- data/lib/PackerFiles/OS/Finder.rb +96 -0
- data/lib/PackerFiles/OS/RHEL/CD.rb +32 -0
- data/lib/PackerFiles/OS/RHEL/Fedora.rb +59 -0
- data/lib/PackerFiles/OS/RHEL/FedoraCD.rb +68 -0
- data/lib/PackerFiles/OS/RHEL/Server.rb +32 -0
- data/lib/PackerFiles/OS/RHEL/Templates/Fedora_Tail_erb.rb +14 -0
- data/lib/PackerFiles/OS/RHEL/Templates/boot_command_fedora_erb.rb +16 -0
- data/lib/PackerFiles/OS/SUSE/Templates/Base_erb.xml +32 -0
- data/lib/PackerFiles/OS/SUSE/Templates/Disk_erb.xml +110 -0
- data/lib/PackerFiles/OS/SUSE/Templates/Keyboard_erb.xml +7 -0
- data/lib/PackerFiles/OS/SUSE/Templates/Locale_erb.xml +18 -0
- data/lib/PackerFiles/OS/SUSE/Templates/Network_erb.xml +143 -0
- data/lib/PackerFiles/OS/SUSE/Templates/Packages_erb.xml +29 -0
- data/lib/PackerFiles/OS/SUSE/Templates/Tail_erb.xml +4 -0
- data/lib/PackerFiles/OS/SUSE/Templates/TimeZone_erb.xml +15 -0
- data/lib/PackerFiles/OS/SUSE/Templates/User_erb.xml +57 -0
- data/lib/PackerFiles/OS/SUSE/Templates/boot_command_erb.rb +23 -0
- data/lib/PackerFiles/OS/SUSE/Templates/command_as_root_erb.rb +1 -0
- data/lib/PackerFiles/OS/SUSE/Templates/disable_root_erb.rb +1 -0
- data/lib/PackerFiles/OS/SUSE/Templates/enable_root_erb.rb +1 -0
- data/lib/PackerFiles/OS/SUSE/Templates/shutdown_command_erb.rb +1 -0
- data/lib/PackerFiles/OS/Ubuntu/CD.rb +81 -0
- data/lib/PackerFiles/OS/Ubuntu/Desktop.rb +50 -0
- data/lib/PackerFiles/OS/Ubuntu/DesktopCD.rb +16 -0
- data/lib/PackerFiles/OS/Ubuntu/Mirrors.rb +103 -0
- data/lib/PackerFiles/OS/Ubuntu/Server.rb +78 -0
- data/lib/PackerFiles/OS/Ubuntu/Templates/Apt_erb.rb +18 -0
- data/lib/PackerFiles/OS/Ubuntu/Templates/boot_command_desktop_erb.rb +36 -0
- data/lib/PackerFiles/OS/Ubuntu/Templates/boot_command_erb.rb +30 -0
- data/lib/PackerFiles/OS/Ubuntu/Templates/ubiquity_erb.rb +8 -0
- data/lib/PackerFiles/OS/example/Doc.txt +8 -0
- data/lib/PackerFiles/Provision/Base.rb +20 -0
- data/lib/PackerFiles/Provision/ChefSolo.rb +90 -0
- data/lib/PackerFiles/Provision/ChefSoloHelper.rb +72 -0
- data/lib/PackerFiles/Provision/Copy.rb +22 -0
- data/lib/PackerFiles/Provision/ExternalScript.rb +43 -0
- data/lib/PackerFiles/Provision/InlineScript.rb +37 -0
- data/lib/PackerFiles/Provision/Provisioners.rb +87 -0
- data/lib/PackerFiles/Provision/example/Provisioners.txt +21 -0
- data/lib/PackerFiles/Utils/AutoZone.rb +96 -0
- data/lib/PackerFiles/Utils/FastestURL.rb +73 -0
- data/lib/PackerFiles/Utils/Generator.rb +34 -0
- data/lib/PackerFiles/Utils/HashSerializer.rb +110 -0
- data/lib/PackerFiles/Utils/Size.rb +44 -0
- data/lib/PackerFiles/Utils/TypeAccessor.rb +71 -0
- data/lib/PackerFiles/Virtual/Hypervisors.rb +72 -0
- data/lib/PackerFiles/Virtual/KVM.rb +119 -0
- data/lib/PackerFiles/Virtual/KVMConverter.rb +79 -0
- data/lib/PackerFiles/Virtual/VMWare.rb +108 -0
- data/lib/PackerFiles/Virtual/VMWareConverter.rb +78 -0
- data/lib/PackerFiles/Virtual/VirtualBox.rb +98 -0
- data/lib/PackerFiles/Virtual/VirtualBoxConverter.rb +75 -0
- data/lib/PackerFiles/Virtual/example/Hypervisors.txt +23 -0
- data/lib/PackerFiles/version.rb +3 -0
- data/lib/PackerFiles.rb +44 -0
- data/spec/core/builder_spec.rb +84 -0
- data/spec/core/cdimage_spec.rb +159 -0
- data/spec/core/disk_spec.rb +191 -0
- data/spec/core/keyboard_spec.rb +36 -0
- data/spec/core/locale_spec.rb +73 -0
- data/spec/core/network_spec.rb +96 -0
- data/spec/core/packages_spec.rb +18 -0
- data/spec/core/timezone_spec.rb +43 -0
- data/spec/core/user_spec.rb +44 -0
- data/spec/core/volume_group_spec.rb +53 -0
- data/spec/os/centos/cd_spec.rb +12 -0
- data/spec/os/centos/data/Server-Script-Provisioner.rb +57 -0
- data/spec/os/centos/data/Server.rb +55 -0
- data/spec/os/centos/data/chef-solo-provisioner.rb +58 -0
- data/spec/os/centos/finder_spec.rb +22 -0
- data/spec/os/centos/templates/boot_command_spec.rb +57 -0
- data/spec/os/centos/templates/disk_spec.rb +79 -0
- data/spec/os/centos/templates/keyboard_spec.rb +18 -0
- data/spec/os/centos/templates/locale_spec.rb +26 -0
- data/spec/os/centos/templates/network_spec.rb +38 -0
- data/spec/os/centos/templates/packages_spec.rb +18 -0
- data/spec/os/centos/templates/timezone_spec.rb +37 -0
- data/spec/os/centos/templates/user_spec.rb +24 -0
- data/spec/os/debian/apt_spec.rb +50 -0
- data/spec/os/debian/cd_spec.rb +30 -0
- data/spec/os/debian/data/7zip.tar.gz +0 -0
- data/spec/os/debian/data/All-sections.rb +60 -0
- data/spec/os/debian/data/Chef-Solo-Provisioner.rb +60 -0
- data/spec/os/debian/data/Copy-Provisioner.rb +61 -0
- data/spec/os/debian/data/External-Script-Provisioner.rb +69 -0
- data/spec/os/debian/data/Missing-CDImage.rb +53 -0
- data/spec/os/debian/data/Missing-VMWare-KVM-sections.rb +51 -0
- data/spec/os/debian/data/Missing-sections.rb +53 -0
- data/spec/os/debian/data/Script-Provisioner.rb +62 -0
- data/spec/os/debian/data/chef-solo-cookbooks/git_setup/Berksfile.lock +32 -0
- data/spec/os/debian/data/chef-solo-cookbooks/git_setup/README.md +81 -0
- data/spec/os/debian/data/chef-solo-cookbooks/git_setup/attributes/default.rb +3 -0
- data/spec/os/debian/data/chef-solo-cookbooks/git_setup/metadata.rb +11 -0
- data/spec/os/debian/data/chef-solo-cookbooks/git_setup/recipes/default.rb +30 -0
- data/spec/os/debian/data/chef-solo.json +5 -0
- data/spec/os/debian/data/test-script.sh +4 -0
- data/spec/os/debian/finder_spec.rb +59 -0
- data/spec/os/debian/mirrors_spec.rb +18 -0
- data/spec/os/debian/preseed_spec.rb +56 -0
- data/spec/os/debian/server_spec.rb +59 -0
- data/spec/os/debian/templates/apt_spec.rb +20 -0
- data/spec/os/debian/templates/boot_command_spec.rb +56 -0
- data/spec/os/debian/templates/disk_spec.rb +81 -0
- data/spec/os/debian/templates/keyboard_spec.rb +18 -0
- data/spec/os/debian/templates/locale_spec.rb +36 -0
- data/spec/os/debian/templates/mirrors_spec.rb +16 -0
- data/spec/os/debian/templates/network_spec.rb +38 -0
- data/spec/os/debian/templates/packages_spec.rb +17 -0
- data/spec/os/debian/templates/timezone_spec.rb +36 -0
- data/spec/os/debian/templates/user_spec.rb +25 -0
- data/spec/os/finder_spec.rb +21 -0
- data/spec/os/rhel/data/Fedora.rb +45 -0
- data/spec/os/rhel/data/Server-Custom.rb +54 -0
- data/spec/os/rhel/data/Server.rb +45 -0
- data/spec/os/rhel/finder_spec.rb +21 -0
- data/spec/os/ubuntu/cd_spec.rb +28 -0
- data/spec/os/ubuntu/data/Desktop.rb +61 -0
- data/spec/os/ubuntu/data/Server.rb +61 -0
- data/spec/os/ubuntu/finder_spec.rb +17 -0
- data/spec/os/ubuntu/mirrors_spec.rb +18 -0
- data/spec/utils/autozone_spec.rb +33 -0
- data/spec/virtual/virtual_box_spec.rb +16 -0
- metadata +405 -0
@@ -0,0 +1,50 @@
|
|
1
|
+
# Requires
|
2
|
+
require_relative 'Server'
|
3
|
+
require_relative 'DesktopCD'
|
4
|
+
|
5
|
+
# OS class that handles details for generating Packer files for Ubuntu
|
6
|
+
# Desktop.
|
7
|
+
module PackerFiles
|
8
|
+
module Ubuntu
|
9
|
+
|
10
|
+
class Desktop < Ubuntu::Server
|
11
|
+
|
12
|
+
# Constructor. Yield self for further initialization
|
13
|
+
def initialize
|
14
|
+
super
|
15
|
+
end
|
16
|
+
|
17
|
+
# Hook function called before normalizing CD Image
|
18
|
+
def cd_image_hook
|
19
|
+
self.CDImage.impl = Ubuntu::DesktopCD.new
|
20
|
+
end
|
21
|
+
|
22
|
+
# Hook for writing into preseed file.
|
23
|
+
def preseed_write_hook(objects)
|
24
|
+
|
25
|
+
# Get Preseed object from the base class.
|
26
|
+
preseed = super
|
27
|
+
|
28
|
+
# Generate Ubiquity specific sections.
|
29
|
+
preseed.eval_file 'Ubuntu/Templates/ubiquity_erb.rb', {'obj' => self}
|
30
|
+
end
|
31
|
+
|
32
|
+
# Name of the preseed file
|
33
|
+
def preseed_file
|
34
|
+
rel = self.CDImage.release
|
35
|
+
arch = self.CDImage.arch
|
36
|
+
name = "preseed-ubuntu-desktop-#{rel}-#{arch}.cfg"
|
37
|
+
File.join(http_dir, name)
|
38
|
+
end
|
39
|
+
|
40
|
+
# Boot Command Override
|
41
|
+
def boot_command
|
42
|
+
file = PackerFiles.DirPath('Ubuntu/Templates/boot_command_desktop_erb.rb')
|
43
|
+
hash = { 'obj' => self}
|
44
|
+
value = PackerFiles.evaluate_erb(file.first, hash)
|
45
|
+
value.split("\n")
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# Requires
|
2
|
+
require_relative 'CD'
|
3
|
+
|
4
|
+
# An implementation for CDImage for Ubuntu Desktop.
|
5
|
+
module PackerFiles
|
6
|
+
module Ubuntu
|
7
|
+
class DesktopCD < CD
|
8
|
+
|
9
|
+
# Override method for getting the ISO name
|
10
|
+
def get_iso_name_pattern
|
11
|
+
'ubuntu-@release@-desktop-@arch@.iso'
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
# Requires
|
2
|
+
require 'open-uri'
|
3
|
+
require 'uri'
|
4
|
+
require 'Utils/AutoZone'
|
5
|
+
require 'Utils/FastestURL'
|
6
|
+
require 'nokogiri'
|
7
|
+
|
8
|
+
# Auto configures the Ubuntu mirror list. This is useful in pre-seeding
|
9
|
+
# the fastest possible mirror.
|
10
|
+
module PackerFiles
|
11
|
+
module Ubuntu
|
12
|
+
class Mirrors
|
13
|
+
|
14
|
+
# default ubuntu mirror
|
15
|
+
@@default = 'http://archive.ubuntu.com/ubuntu'
|
16
|
+
|
17
|
+
# Default ubuntu mirror list for any country.
|
18
|
+
@@mirrors = 'http://mirrors.ubuntu.com/@country@.txt'
|
19
|
+
|
20
|
+
# Default Master archive mirror list
|
21
|
+
@@master = 'https://launchpad.net/ubuntu/+archivemirrors'
|
22
|
+
|
23
|
+
# accessors
|
24
|
+
attr_reader :hosts
|
25
|
+
attr_reader :best
|
26
|
+
attr_reader :proxy
|
27
|
+
|
28
|
+
# Constructor
|
29
|
+
def initialize
|
30
|
+
|
31
|
+
# A Single web page get more than this (in seconds) is SLOW
|
32
|
+
limit = 1
|
33
|
+
|
34
|
+
# No. of trials for a web page
|
35
|
+
trials = 4
|
36
|
+
|
37
|
+
# Get the name of the http proxy
|
38
|
+
@proxy = ENV['http_proxy']
|
39
|
+
|
40
|
+
# Get the host list of mirrors for this country
|
41
|
+
code = Utils::AutoZone.new.country_code.upcase
|
42
|
+
@hosts = country_mirror(code)
|
43
|
+
if @hosts.empty?
|
44
|
+
@hosts = [@@default] if @hosts.empty?
|
45
|
+
@best = URI::parse(@@default)
|
46
|
+
else
|
47
|
+
@hosts = filter_status_unknown.compact
|
48
|
+
f = Utils::FastestURL.new(limit, trials)
|
49
|
+
all = f.best_urls(@hosts).flatten
|
50
|
+
begin
|
51
|
+
@best = URI::parse(all.first)
|
52
|
+
rescue Exception => e
|
53
|
+
puts "Exception: #{e}, All: #{all.to_s}"
|
54
|
+
raise e
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# Given the country code, get a list of mirror sites that match
|
60
|
+
# the country code.
|
61
|
+
private
|
62
|
+
def country_mirror(code)
|
63
|
+
url = @@mirrors.gsub('@country@', code)
|
64
|
+
contents = open(url) {|f| f.read}
|
65
|
+
return contents.split("\n")
|
66
|
+
end
|
67
|
+
|
68
|
+
# Given a list of hosts which can act as mirrors, filter out those
|
69
|
+
# hosts whose status is unknown, as they can cause updates and
|
70
|
+
# new installation packages to fail.
|
71
|
+
private
|
72
|
+
def filter_status_unknown
|
73
|
+
|
74
|
+
# Parse the HTML from the master index archive.
|
75
|
+
page = Nokogiri::HTML(open(@@master))
|
76
|
+
|
77
|
+
# Iterate through the list of hosts
|
78
|
+
@hosts.map {|host|
|
79
|
+
node = page.css('td').select {|node|
|
80
|
+
aref = node.css('a')
|
81
|
+
if aref.empty?
|
82
|
+
false
|
83
|
+
else
|
84
|
+
aref.first['href'] == host
|
85
|
+
end
|
86
|
+
}
|
87
|
+
if node.empty?
|
88
|
+
nil
|
89
|
+
else
|
90
|
+
text = node.first.next_element.next_element.text
|
91
|
+
if text.include?('Last update unknown')
|
92
|
+
nil
|
93
|
+
else
|
94
|
+
host
|
95
|
+
end
|
96
|
+
end
|
97
|
+
}
|
98
|
+
end
|
99
|
+
|
100
|
+
end #class Mirror
|
101
|
+
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# Requires
|
2
|
+
require 'OS/Debian/Server'
|
3
|
+
require_relative 'CD'
|
4
|
+
require_relative 'Mirrors'
|
5
|
+
|
6
|
+
# OS class that handles details for generating Packer files for Ubuntu
|
7
|
+
# Servers.
|
8
|
+
module PackerFiles
|
9
|
+
module Ubuntu
|
10
|
+
|
11
|
+
class Server < Debian::Server
|
12
|
+
|
13
|
+
# Constructor. Yield self for further initialization
|
14
|
+
def initialize
|
15
|
+
super
|
16
|
+
end
|
17
|
+
|
18
|
+
# Hook function called before normalizing CD Image
|
19
|
+
def cd_image_hook
|
20
|
+
self.CDImage.impl = Ubuntu::CD.new
|
21
|
+
end
|
22
|
+
|
23
|
+
# Hook for writing into preseed file.
|
24
|
+
def preseed_write_hook(objects)
|
25
|
+
|
26
|
+
# Preseed file by evaluating templates @ Debian folder.
|
27
|
+
preseed = Debian::Preseed.new(preseed_file)
|
28
|
+
|
29
|
+
# Convert objects into Preseed configuration.
|
30
|
+
objects.each do |obj|
|
31
|
+
if obj.is_a? Debian::Apt
|
32
|
+
preseed.convert obj, 'Ubuntu/Templates'
|
33
|
+
else
|
34
|
+
preseed.convert obj, 'Debian/Templates'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Generate fastest debian mirrors
|
39
|
+
preseed.eval_file 'Debian/Templates/Mirrors_erb.rb',
|
40
|
+
{'obj' => Ubuntu::Mirrors.new}
|
41
|
+
|
42
|
+
# Return the preseed object for further customization
|
43
|
+
# by derived classes.
|
44
|
+
return preseed
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
# Name of the preseed file
|
49
|
+
def preseed_file
|
50
|
+
rel = self.CDImage.release
|
51
|
+
arch = self.CDImage.arch
|
52
|
+
name = "preseed-ubuntu-server-#{rel}-#{arch}.cfg"
|
53
|
+
File.join(http_dir, name)
|
54
|
+
end
|
55
|
+
|
56
|
+
# Boot Command Override
|
57
|
+
def boot_command
|
58
|
+
file = PackerFiles.DirPath('Ubuntu/Templates/boot_command_erb.rb')
|
59
|
+
hash = { 'obj' => self, 'network' => self.Network }
|
60
|
+
value = PackerFiles.evaluate_erb(file.first, hash)
|
61
|
+
value.split("\n")
|
62
|
+
end
|
63
|
+
|
64
|
+
# Guest OS Type override
|
65
|
+
def guest_os_type
|
66
|
+
return "Ubuntu_64" if (self.CDImage.arch == "amd64")
|
67
|
+
return "Ubuntu"
|
68
|
+
end
|
69
|
+
|
70
|
+
# VMWare Guest OS Type override
|
71
|
+
def vmware_guest_os_type
|
72
|
+
return "ubuntu-64" if (self.CDImage.arch == "amd64")
|
73
|
+
return "ubuntu"
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# Apt Configuration Section
|
2
|
+
apt-cdrom-setup apt-setup/cdrom/set-first boolean false
|
3
|
+
apt-mirror-setup apt-setup/use_mirror boolean true
|
4
|
+
popularity-contest popularity-contest/participate boolean false
|
5
|
+
tasksel tasksel/first multiselect <%= @obj.tasks.join(',') %>
|
6
|
+
d-i apt-setup/restricted boolean <%= @obj.non_free %>
|
7
|
+
d-i apt-setup/multiverse boolean <%= @obj.non_free %>
|
8
|
+
d-i apt-setup/universe boolean <%= @obj.contrib %>
|
9
|
+
d-i pkgsel/upgrade select <%= @obj.upgrades %>
|
10
|
+
d-i pkgsel/update-policy select unattended-upgrades
|
11
|
+
d-i apt-setup/services-select multiselect security, updates
|
12
|
+
|
13
|
+
# Basic OS Settings and Configuration
|
14
|
+
d-i base-installer/kernel/override-image string <%= @obj.kernel %>
|
15
|
+
d-i finish-install/reboot_in_progress note
|
16
|
+
d-i grub-installer/only_debian boolean true
|
17
|
+
d-i grub-installer/with_other_os boolean true
|
18
|
+
|
@@ -0,0 +1,36 @@
|
|
1
|
+
<esc><esc><esc>
|
2
|
+
<enter><wait>
|
3
|
+
<% if @obj.CDImage.arch == "amd64" -%>
|
4
|
+
/casper/vmlinuz.efi <wait>
|
5
|
+
<% else -%>
|
6
|
+
/casper/vmlinuz <wait>
|
7
|
+
<% end -%>
|
8
|
+
keyboard-configuration/layoutcode=<%= @obj.Keyboard.layout %>
|
9
|
+
noprompt
|
10
|
+
automatic-ubiquity
|
11
|
+
boot=casper
|
12
|
+
initrd=/casper/initrd.lz
|
13
|
+
quiet
|
14
|
+
splash
|
15
|
+
auto=true priority=critical
|
16
|
+
<% preseed = @obj.preseed_file.gsub(@obj.http_dir,'').gsub('/', '') -%>
|
17
|
+
<% if @obj.Network.nil? -%>
|
18
|
+
url=http://{{user `host`}}:{{user `port`}}/<%= preseed -%> <wait>
|
19
|
+
<% elsif !@obj.Network.is_static? -%>
|
20
|
+
url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/<%= preseed -%> <wait>
|
21
|
+
<% else -%>
|
22
|
+
url=http://{{user `host`}}:{{user `port`}}/<%= preseed -%> <wait>
|
23
|
+
<% end -%>
|
24
|
+
<% if !@obj.Network.nil? && @obj.Network.is_static? -%>
|
25
|
+
netcfg/disable_autoconfig=true <wait>
|
26
|
+
netcfg/get_ipaddress=<%= @obj.Network.ip %> <wait>
|
27
|
+
netcfg/get_netmask=<%= @obj.Network.mask %> <wait>
|
28
|
+
netcfg/get_gateway=<%= @obj.Network.gateway %> <wait>
|
29
|
+
netcfg/get_nameservers=<%= @obj.Network.dns.join(" ") %> <wait>
|
30
|
+
netcfg/confirm_static=true <wait>
|
31
|
+
netcfg/dhcp_timeout=60 <wait>
|
32
|
+
netcfg/dhcpv6_timeout=60 <wait>
|
33
|
+
netcfg/get_hostname=unassigned-hostname <wait>
|
34
|
+
netcfg/get_domain=unassigned-domain <wait>
|
35
|
+
<% end -%>
|
36
|
+
-- <enter> <wait>
|
@@ -0,0 +1,30 @@
|
|
1
|
+
<esc><wait>
|
2
|
+
<esc><wait>
|
3
|
+
<enter><wait>
|
4
|
+
/install/vmlinuz <wait>
|
5
|
+
initrd=/install/initrd.gz <wait>
|
6
|
+
fb=false <wait>
|
7
|
+
noapic <wait>
|
8
|
+
auto=true priority=critical <wait>
|
9
|
+
<% preseed = @obj.preseed_file.gsub(@obj.http_dir,'').gsub('/', '') -%>
|
10
|
+
<% if @network.nil? -%>
|
11
|
+
preseed/url=http://{{user `host`}}:{{user `port`}}/<%= preseed -%> <wait>
|
12
|
+
<% elsif !@network.is_static? -%>
|
13
|
+
preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/<%= preseed -%> <wait>
|
14
|
+
<% else -%>
|
15
|
+
preseed/url=http://{{user `host`}}:{{user `port`}}/<%= preseed -%> <wait>
|
16
|
+
<% end -%>
|
17
|
+
<% if !@network.nil? && @network.is_static? -%>
|
18
|
+
netcfg/disable_autoconfig=true <wait>
|
19
|
+
netcfg/get_ipaddress=<%= @network.ip %> <wait>
|
20
|
+
netcfg/get_netmask=<%= @network.mask %> <wait>
|
21
|
+
netcfg/get_gateway=<%= @network.gateway %> <wait>
|
22
|
+
netcfg/get_nameservers=<%= @network.dns.join(" ") %> <wait>
|
23
|
+
netcfg/confirm_static=true <wait>
|
24
|
+
netcfg/dhcp_timeout=60 <wait>
|
25
|
+
netcfg/dhcpv6_timeout=60 <wait>
|
26
|
+
netcfg/get_hostname=unassigned-hostname <wait>
|
27
|
+
netcfg/get_domain=unassigned-domain <wait>
|
28
|
+
<% end -%>
|
29
|
+
-- <wait>
|
30
|
+
<enter><wait>
|
@@ -0,0 +1,8 @@
|
|
1
|
+
# Various Parameters for Ubiquity to work properly.
|
2
|
+
ubiquity languagechooser/language-name select English
|
3
|
+
ubiquity ubiquity/reboot boolean true
|
4
|
+
<% if !@obj.Packages.list.nil? -%>
|
5
|
+
ubiquity ubiquity/success_command string in-target apt-get --yes install <%= @obj.Packages.list.join(' ') %>
|
6
|
+
<% end -%>
|
7
|
+
|
8
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# Requires
|
2
|
+
require 'Utils/HashSerializer'
|
3
|
+
|
4
|
+
# The Remote Copier class is used for copying local files or directories
|
5
|
+
# into the remote host.
|
6
|
+
module PackerFiles
|
7
|
+
module Provision
|
8
|
+
class Base < Utils::HashSerializer
|
9
|
+
|
10
|
+
# Various accessors common for all Provisioners.
|
11
|
+
hash_variable :only, Array
|
12
|
+
hash_variable :except, Array
|
13
|
+
hash_variable :type
|
14
|
+
|
15
|
+
# attribute accessor
|
16
|
+
attr_accessor :os
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
# Requires
|
2
|
+
require 'json'
|
3
|
+
require_relative 'Base'
|
4
|
+
require_relative 'ChefSoloHelper'
|
5
|
+
|
6
|
+
# The Chef Solo class is used for executing a series of Cookbooks
|
7
|
+
# inside the VM, using chef solo provisioner.
|
8
|
+
module PackerFiles
|
9
|
+
module Provision
|
10
|
+
class ChefSolo < Base
|
11
|
+
|
12
|
+
# Various accessors
|
13
|
+
hash_variable :cookbook_paths, Array, :convert_cookbook_paths
|
14
|
+
hash_variable :data_bags_path
|
15
|
+
hash_variable :encrypted_data_bag_secret_path
|
16
|
+
hash_variable :execute_command
|
17
|
+
hash_variable :install_command
|
18
|
+
hash_variable :json, String, :convert_to_json
|
19
|
+
hash_variable :prevent_sudo, String, :convert_sudo_to_boolean
|
20
|
+
hash_variable :remote_cookbook_paths
|
21
|
+
hash_variable :roles_path
|
22
|
+
hash_variable :run_list, Array
|
23
|
+
hash_variable :skip_install, String, :convert_skip_to_boolean
|
24
|
+
hash_variable :staging_directory
|
25
|
+
|
26
|
+
# Attribute accessor which is not converted into a hash serializer
|
27
|
+
#attr_accessor :download_cookbooks
|
28
|
+
|
29
|
+
# JSON converter
|
30
|
+
def convert_to_json
|
31
|
+
# Check if it is a string and if so parse it into JSON
|
32
|
+
begin
|
33
|
+
return JSON.parse(self.json)
|
34
|
+
rescue JSON::ParserError => e
|
35
|
+
return JSON.parse(File.read(self.json))
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# Cookbook Path converter
|
40
|
+
def convert_cookbook_paths
|
41
|
+
self.cookbook_paths.map {|p| File.absolute_path(p)}
|
42
|
+
end
|
43
|
+
|
44
|
+
# Boolean converter for prevent_sudo
|
45
|
+
def convert_sudo_to_boolean
|
46
|
+
(self.prevent_sudo.to_i > 0) ? true : false
|
47
|
+
end
|
48
|
+
|
49
|
+
# Boolean converter for skip_install
|
50
|
+
def convert_skip_to_boolean
|
51
|
+
(self.skip_install.to_i > 0) ? true : false
|
52
|
+
end
|
53
|
+
|
54
|
+
# Constructor yields self
|
55
|
+
def initialize(&block)
|
56
|
+
yield self if block_given?
|
57
|
+
@type = 'chef-solo'
|
58
|
+
end
|
59
|
+
|
60
|
+
# If chef-solo has to work, all the dependent cookbooks also
|
61
|
+
# needs to be found in one of the cookbook folders. So we need
|
62
|
+
# to intercept the to_hash call to extract cookbooks inside a
|
63
|
+
# .tar.gz bundle.
|
64
|
+
def to_hash(*args)
|
65
|
+
|
66
|
+
# The Provisioner usually passes the OS class as it's first
|
67
|
+
# argument
|
68
|
+
os = args[0]
|
69
|
+
|
70
|
+
# Some cookbook paths are special in the sense, they are .tar.gz
|
71
|
+
# bundles. The code fragment handles that special case.
|
72
|
+
convert_cookbook_paths.each_with_index do |path, index|
|
73
|
+
next if !path.end_with?('.tar.gz')
|
74
|
+
temp = Dir.mktmpdir('dep', os.OutDir)
|
75
|
+
helper = ChefSoloHelper.new(path)
|
76
|
+
local = helper.download_files(os.OutDir)
|
77
|
+
helper.extract_files(temp, local)
|
78
|
+
@cookbook_paths.push(temp)
|
79
|
+
end
|
80
|
+
|
81
|
+
# Remove all the cookbooks that end with .tar.gz
|
82
|
+
@cookbook_paths.delete_if {|cb| cb.end_with?('.tar.gz')}
|
83
|
+
|
84
|
+
# call back the original to_hash function.
|
85
|
+
super
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# Requires
|
2
|
+
require 'uri'
|
3
|
+
require 'open-uri'
|
4
|
+
require 'rubygems/package'
|
5
|
+
require 'zlib'
|
6
|
+
require 'fileutils'
|
7
|
+
|
8
|
+
# Chef Solo helper is useful to download [remote tar.gz] files into a local
|
9
|
+
# folder.
|
10
|
+
module PackerFiles
|
11
|
+
module Provision
|
12
|
+
class ChefSoloHelper
|
13
|
+
|
14
|
+
# Just remember the name of the file
|
15
|
+
attr_accessor :tar_gz_file
|
16
|
+
|
17
|
+
# Initialize the helper with the path of the .tar.gz file
|
18
|
+
def initialize(tar_gz_file)
|
19
|
+
@tar_gz_file = tar_gz_file
|
20
|
+
end
|
21
|
+
|
22
|
+
# Given a top level directory, and the tar_gz_file, download
|
23
|
+
# it locally if it is a remote file.
|
24
|
+
def download_files(top_dir)
|
25
|
+
url = URI::parse(@tar_gz_file)
|
26
|
+
if url.scheme.nil?
|
27
|
+
return @tar_gz_file
|
28
|
+
else
|
29
|
+
name = File.join(top_dir, File.basename(@tar_gz_file))
|
30
|
+
content = open(@tar_gz_file) {|f| f.read}
|
31
|
+
File.write(name, content)
|
32
|
+
return name
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# Given a list of .tar.gz files, untar and ungzip them
|
37
|
+
def extract_files(dest_dir, file)
|
38
|
+
untar(ungzip(file), dest_dir)
|
39
|
+
end
|
40
|
+
|
41
|
+
# un-gzips the given IO, returning the decompressed version
|
42
|
+
# as a StringIO
|
43
|
+
private
|
44
|
+
def ungzip(tarfile)
|
45
|
+
zip = Zlib::GzipReader.open(tarfile)
|
46
|
+
unzip = StringIO.new(zip.read)
|
47
|
+
zip.close
|
48
|
+
unzip
|
49
|
+
end
|
50
|
+
|
51
|
+
# untars the given IO into the specified directory
|
52
|
+
private
|
53
|
+
def untar(io, dest_dir)
|
54
|
+
Gem::Package::TarReader.new io do |tar|
|
55
|
+
tar.each do |tarfile|
|
56
|
+
dest = File.join(dest_dir, tarfile.full_name)
|
57
|
+
if tarfile.directory?
|
58
|
+
FileUtils.mkdir_p(dest)
|
59
|
+
next
|
60
|
+
end
|
61
|
+
dir = File.dirname(dest)
|
62
|
+
FileUtils.mkdir_p dir unless File.directory?(dir)
|
63
|
+
File.open dest, "wb" do |f|
|
64
|
+
f.print tarfile.read
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# Requires
|
2
|
+
require_relative 'Base'
|
3
|
+
|
4
|
+
# The Remote Copier class is used for copying local files or directories
|
5
|
+
# into the remote host.
|
6
|
+
module PackerFiles
|
7
|
+
module Provision
|
8
|
+
class Copy < Base
|
9
|
+
|
10
|
+
# Various accessors
|
11
|
+
hash_variable :source
|
12
|
+
hash_variable :destination
|
13
|
+
|
14
|
+
# Constructor yields self
|
15
|
+
def initialize(&block)
|
16
|
+
yield self if block_given?
|
17
|
+
@type = 'file'
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# Requires
|
2
|
+
require_relative 'Base'
|
3
|
+
|
4
|
+
# The External script class is used for executing a series of external scripts
|
5
|
+
# inside the VM.
|
6
|
+
module PackerFiles
|
7
|
+
module Provision
|
8
|
+
class ExternalScript < Base
|
9
|
+
|
10
|
+
# Various accessors
|
11
|
+
hash_variable :execute_command
|
12
|
+
hash_variable :scripts, Array, :convert_scripts
|
13
|
+
hash_variable :binary, Integer, :convert_to_boolean
|
14
|
+
hash_variable :environment_vars, Hash, :convert_env_vars
|
15
|
+
|
16
|
+
# Conversion function for environment variables.
|
17
|
+
def convert_env_vars
|
18
|
+
array = []
|
19
|
+
self.environment_vars.each_pair do |var, value|
|
20
|
+
array.push("#{var}=#{value.to_s}")
|
21
|
+
end
|
22
|
+
array
|
23
|
+
end
|
24
|
+
|
25
|
+
# Conversion function for boolean
|
26
|
+
def convert_to_boolean
|
27
|
+
(self.binary > 0) ? true : false
|
28
|
+
end
|
29
|
+
|
30
|
+
# Conversion function for scripts
|
31
|
+
def convert_scripts
|
32
|
+
self.scripts.map {|script| File.absolute_path(script)}
|
33
|
+
end
|
34
|
+
|
35
|
+
# Constructor yields self
|
36
|
+
def initialize(&block)
|
37
|
+
yield self if block_given?
|
38
|
+
@type = 'shell'
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# Requires
|
2
|
+
require_relative 'Base'
|
3
|
+
|
4
|
+
# The Inline script class is used for executing a series of script commands
|
5
|
+
# inside the VM.
|
6
|
+
module PackerFiles
|
7
|
+
module Provision
|
8
|
+
class InlineScript < Base
|
9
|
+
|
10
|
+
# Various accessors
|
11
|
+
hash_variable :execute_command
|
12
|
+
hash_variable :environment_vars, Hash, :convert_env_vars
|
13
|
+
hash_variable :inline, String, :convert_inline
|
14
|
+
|
15
|
+
# Conversion function for environment variables.
|
16
|
+
def convert_env_vars
|
17
|
+
array = []
|
18
|
+
self.environment_vars.each_pair do |var, value|
|
19
|
+
array.push("#{var}=#{value.to_s}")
|
20
|
+
end
|
21
|
+
array
|
22
|
+
end
|
23
|
+
|
24
|
+
# Conversion function for inline commands
|
25
|
+
def convert_inline
|
26
|
+
self.inline.split("\n").map {|line| line.strip}
|
27
|
+
end
|
28
|
+
|
29
|
+
# Constructor yields self
|
30
|
+
def initialize(&block)
|
31
|
+
yield self if block_given?
|
32
|
+
@type = 'shell'
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|