comfy 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +2 -0
- data/.travis.yml +46 -0
- data/Gemfile +4 -0
- data/LICENSE +13 -0
- data/README.md +131 -0
- data/Rakefile +18 -0
- data/bin/comfy +4 -0
- data/comfy.gemspec +36 -0
- data/config/comfy.yml +20 -0
- data/lib/comfy/command_executioner.rb +225 -0
- data/lib/comfy/creator.rb +200 -0
- data/lib/comfy/errors/invalid_distribution_version_error.rb +1 -0
- data/lib/comfy/errors/no_such_distribution_version_error.rb +1 -0
- data/lib/comfy/errors/packer_error.rb +1 -0
- data/lib/comfy/errors/packer_execution_error.rb +1 -0
- data/lib/comfy/errors/packer_validation_error.rb +1 -0
- data/lib/comfy/errors.rb +4 -0
- data/lib/comfy/extensions/yell.rb +8 -0
- data/lib/comfy/settings.rb +15 -0
- data/lib/comfy/templater.rb +62 -0
- data/lib/comfy/version.rb +3 -0
- data/lib/comfy.rb +18 -0
- data/lib/templates/centos/centos.cfg.erb +47 -0
- data/lib/templates/centos/centos.description +20 -0
- data/lib/templates/centos/files/10-ipv6.conf +5 -0
- data/lib/templates/centos/files/check-mk-agent-meta-checks-2.0-1.noarch.rpm +0 -0
- data/lib/templates/centos/files/check-mk-agent-meta-key-1.0-1.noarch.rpm +0 -0
- data/lib/templates/centos/files/cloud.cfg +101 -0
- data/lib/templates/centos/files/fail2ban.local +3 -0
- data/lib/templates/centos/files/getty@ttyS0.service +47 -0
- data/lib/templates/centos/files/grub +11 -0
- data/lib/templates/centos/files/iptables-multiport.local +6 -0
- data/lib/templates/centos/files/jail.local +17 -0
- data/lib/templates/centos/files/krb5.conf +181 -0
- data/lib/templates/centos/files/ntp.conf +61 -0
- data/lib/templates/centos/files/pakiti-2.1.5-1.noarch.rpm +0 -0
- data/lib/templates/centos/files/sshd_config +152 -0
- data/lib/templates/centos/files/xen-domU.conf +1 -0
- data/lib/templates/centos/scripts/init.sh +83 -0
- data/lib/templates/debian/debian.cfg.erb +80 -0
- data/lib/templates/debian/debian.description +28 -0
- data/lib/templates/debian/files/.bashrc +112 -0
- data/lib/templates/debian/files/.gitconfig +7 -0
- data/lib/templates/debian/files/10-ipv6.conf +5 -0
- data/lib/templates/debian/files/DEPOT-GPG-KEY.cfg +32 -0
- data/lib/templates/debian/files/RPM-GPG-KEY-CERIT-SC.cfg +30 -0
- data/lib/templates/debian/files/backports.list +2 -0
- data/lib/templates/debian/files/cerit-cloudinit.list +2 -0
- data/lib/templates/debian/files/cloud.cfg +102 -0
- data/lib/templates/debian/files/depot.list +4 -0
- data/lib/templates/debian/files/depot_all.pref +6 -0
- data/lib/templates/debian/files/depot_check_mk.pref +5 -0
- data/lib/templates/debian/files/fail2ban.local +3 -0
- data/lib/templates/debian/files/getty@ttyS0.service +47 -0
- data/lib/templates/debian/files/grub +34 -0
- data/lib/templates/debian/files/inittab +69 -0
- data/lib/templates/debian/files/interfaces +15 -0
- data/lib/templates/debian/files/iptables-multiport.local +6 -0
- data/lib/templates/debian/files/jail.local +17 -0
- data/lib/templates/debian/files/krb5.conf +181 -0
- data/lib/templates/debian/files/meta-misc.list +2 -0
- data/lib/templates/debian/files/modules +15 -0
- data/lib/templates/debian/files/ntp.conf +61 -0
- data/lib/templates/debian/files/pakiti_2.1.5-2_all.deb +0 -0
- data/lib/templates/debian/files/sshd_config +131 -0
- data/lib/templates/debian/scripts/debian_cloud_script.sh +80 -0
- data/lib/templates/docker/docker.cfg.erb +87 -0
- data/lib/templates/docker/docker.description +21 -0
- data/lib/templates/docker/files/10-ipv6.conf +5 -0
- data/lib/templates/docker/files/DEPOT-GPG-KEY.cfg +32 -0
- data/lib/templates/docker/files/RPM-GPG-KEY-CERIT-SC.cfg +30 -0
- data/lib/templates/docker/files/cloud.cfg +109 -0
- data/lib/templates/docker/files/depot.list +4 -0
- data/lib/templates/docker/files/depot_all.pref +6 -0
- data/lib/templates/docker/files/depot_check_mk.pref +5 -0
- data/lib/templates/docker/files/docker.list +1 -0
- data/lib/templates/docker/files/fail2ban.local +3 -0
- data/lib/templates/docker/files/grub +34 -0
- data/lib/templates/docker/files/interfaces +15 -0
- data/lib/templates/docker/files/iptables-multiport.local +6 -0
- data/lib/templates/docker/files/jail.local +17 -0
- data/lib/templates/docker/files/krb5.conf +181 -0
- data/lib/templates/docker/files/meta-misc.list +2 -0
- data/lib/templates/docker/files/modules +15 -0
- data/lib/templates/docker/files/ntp.conf +61 -0
- data/lib/templates/docker/files/pakiti_2.1.5-2_all.deb +0 -0
- data/lib/templates/docker/files/sshd_config +131 -0
- data/lib/templates/docker/files/ttyS0.conf +11 -0
- data/lib/templates/docker/scripts/init.sh +65 -0
- data/lib/templates/packer.erb +93 -0
- data/lib/templates/scientificlinux/files/10-ipv6.conf +5 -0
- data/lib/templates/scientificlinux/files/check-mk-agent-meta-checks-2.0-1.noarch.rpm +0 -0
- data/lib/templates/scientificlinux/files/check-mk-agent-meta-key-1.0-1.noarch.rpm +0 -0
- data/lib/templates/scientificlinux/files/cloud.cfg +101 -0
- data/lib/templates/scientificlinux/files/fail2ban.local +3 -0
- data/lib/templates/scientificlinux/files/getty@ttyS0.service +47 -0
- data/lib/templates/scientificlinux/files/grub +10 -0
- data/lib/templates/scientificlinux/files/iptables-multiport.local +6 -0
- data/lib/templates/scientificlinux/files/jail.local +17 -0
- data/lib/templates/scientificlinux/files/krb5.conf +181 -0
- data/lib/templates/scientificlinux/files/ntp.conf +61 -0
- data/lib/templates/scientificlinux/files/pakiti-2.1.5-1.noarch.rpm +0 -0
- data/lib/templates/scientificlinux/files/sshd_config +150 -0
- data/lib/templates/scientificlinux/files/xen-domU.conf +1 -0
- data/lib/templates/scientificlinux/scientificlinux.cfg.erb +57 -0
- data/lib/templates/scientificlinux/scientificlinux.description +19 -0
- data/lib/templates/scientificlinux/scripts/init.sh +92 -0
- data/lib/templates/ubuntu/files/10-ipv6.conf +5 -0
- data/lib/templates/ubuntu/files/DEPOT-GPG-KEY.cfg +32 -0
- data/lib/templates/ubuntu/files/RPM-GPG-KEY-CERIT-SC.cfg +30 -0
- data/lib/templates/ubuntu/files/cloud.cfg +109 -0
- data/lib/templates/ubuntu/files/depot.list +4 -0
- data/lib/templates/ubuntu/files/depot_all.pref +6 -0
- data/lib/templates/ubuntu/files/depot_check_mk.pref +5 -0
- data/lib/templates/ubuntu/files/fail2ban.local +3 -0
- data/lib/templates/ubuntu/files/grub +34 -0
- data/lib/templates/ubuntu/files/interfaces +15 -0
- data/lib/templates/ubuntu/files/iptables-multiport.local +6 -0
- data/lib/templates/ubuntu/files/jail.local +17 -0
- data/lib/templates/ubuntu/files/krb5.conf +181 -0
- data/lib/templates/ubuntu/files/meta-misc.list +2 -0
- data/lib/templates/ubuntu/files/modules +15 -0
- data/lib/templates/ubuntu/files/ntp.conf +61 -0
- data/lib/templates/ubuntu/files/pakiti_2.1.5-2_all.deb +0 -0
- data/lib/templates/ubuntu/files/sshd_config +131 -0
- data/lib/templates/ubuntu/files/ttyS0.conf +11 -0
- data/lib/templates/ubuntu/scripts/init.sh +54 -0
- data/lib/templates/ubuntu/ubuntu.cfg.erb +87 -0
- data/lib/templates/ubuntu/ubuntu.description +21 -0
- data/schema/distribution_descriptor.schema +241 -0
- metadata +374 -0
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
require 'fileutils'
|
|
2
|
+
require 'mixlib/shellout'
|
|
3
|
+
require 'tmpdir'
|
|
4
|
+
require 'json'
|
|
5
|
+
require 'json-schema'
|
|
6
|
+
require 'cloud-appliance-descriptor'
|
|
7
|
+
|
|
8
|
+
# Creates given virtual machine images.
|
|
9
|
+
class Comfy::Creator
|
|
10
|
+
attr_accessor :data
|
|
11
|
+
|
|
12
|
+
TIMESTAMP_FORMAT = '%Y%m%d%H%M'
|
|
13
|
+
|
|
14
|
+
NEEDLE_REPLACEMENTS = {
|
|
15
|
+
:$v => lambda { |instance| instance.send(:version_string) },
|
|
16
|
+
:$t => lambda { |instance| Time.new.strftime(TIMESTAMP_FORMAT) },
|
|
17
|
+
:$n => lambda { |instance| instance.data[:distro]['name'] },
|
|
18
|
+
:$g => lambda { |instance| instance.data[:groups].join(',') }
|
|
19
|
+
}
|
|
20
|
+
REPLACEMENT_REGEX = /\$[a-zA-Z]/
|
|
21
|
+
|
|
22
|
+
# Creates a creator instance.
|
|
23
|
+
#
|
|
24
|
+
# @param options [Hashie::Mash] hash-like structure with options
|
|
25
|
+
def initialize(options)
|
|
26
|
+
@data = options.clone
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Method representing thw whole creation process. Prepares enviroment,
|
|
30
|
+
# prepare files and starts packer job.
|
|
31
|
+
def create
|
|
32
|
+
logger.info('Preparing for image creation...')
|
|
33
|
+
|
|
34
|
+
data[:server_dir] = Dir.mktmpdir('comfy')
|
|
35
|
+
logger.debug("Server root directory: #{data[:server_dir]}")
|
|
36
|
+
|
|
37
|
+
prepare_data
|
|
38
|
+
logger.debug("Prepared data: #{data}")
|
|
39
|
+
|
|
40
|
+
templater = Comfy::Templater.new data
|
|
41
|
+
templater.prepare_files
|
|
42
|
+
|
|
43
|
+
packer_file = "#{data[:server_dir]}/#{data[:distribution]}.packer"
|
|
44
|
+
run_packer(packer_file)
|
|
45
|
+
|
|
46
|
+
# let's create cloud appliance descriptor files
|
|
47
|
+
if data[:description]
|
|
48
|
+
data[:formats].each do |format|
|
|
49
|
+
name = data[:distribution]
|
|
50
|
+
major = data[:distro][:version]['major_version']
|
|
51
|
+
minor = data[:distro][:version]['minor_version']
|
|
52
|
+
dir = File.join(data[:'output-dir'], "comfy_#{name}-#{major}.#{minor}_#{format}/")
|
|
53
|
+
File.write(File.join(dir, "#{data[:identifier]}.json"), description(format))
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# Cleans everything from temporary directory
|
|
59
|
+
def clean
|
|
60
|
+
if data[:server_dir]
|
|
61
|
+
logger.debug("Cleaning temporary directory #{data[:server_dir]}.")
|
|
62
|
+
FileUtils.remove_dir(data[:server_dir])
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
private
|
|
67
|
+
|
|
68
|
+
# Method wrapping usage of packer tool.
|
|
69
|
+
#
|
|
70
|
+
# @param packer_file descriptor file with info for packer processing.
|
|
71
|
+
def run_packer(packer_file)
|
|
72
|
+
logger.info("Calling Packer - building distribution: '#{data[:distribution]}'.")
|
|
73
|
+
packer = Mixlib::ShellOut.new("packer validate #{packer_file}")
|
|
74
|
+
packer.run_command
|
|
75
|
+
|
|
76
|
+
fail Comfy::Errors::PackerValidationError, "Packer validation failed for distribution '#{data[:distribution]}': #{packer.stdout}" if packer.error?
|
|
77
|
+
|
|
78
|
+
packer = Mixlib::ShellOut.new("packer build -parallel=false #{packer_file}", timeout: 5400)
|
|
79
|
+
packer.live_stream = logger
|
|
80
|
+
packer.run_command
|
|
81
|
+
|
|
82
|
+
fail Comfy::Errors::PackerExecutionError, "Packer finished with error for distribution '#{data[:distribution]}': #{packer.stderr}" if packer.error?
|
|
83
|
+
|
|
84
|
+
logger.info("Packer finished successfully for distribution '#{data[:distribution]}'")
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# Preparation of various data. Method prepares description file for packer and distribution
|
|
88
|
+
# preseed / kickstart file.
|
|
89
|
+
def prepare_data
|
|
90
|
+
description_file = "#{data[:'template-dir']}/#{data[:distribution]}/#{data[:distribution]}.description"
|
|
91
|
+
JSON::Validator.validate!(Comfy::DESCRIPTION_SCHEMA_FILE, description_file)
|
|
92
|
+
|
|
93
|
+
description = File.read(description_file)
|
|
94
|
+
data[:distro] = JSON.parse(description)
|
|
95
|
+
logger.debug("Data from description file: #{data[:distro]}")
|
|
96
|
+
|
|
97
|
+
data[:distro][:version] = choose_version
|
|
98
|
+
logger.debug("Version selected for build: #{data[:distro][:version]}")
|
|
99
|
+
|
|
100
|
+
data[:provisioners] = {}
|
|
101
|
+
data[:provisioners][:scripts] = Dir.glob(File.join(data[:'template-dir'], data[:distribution], 'scripts', '*'))
|
|
102
|
+
data[:provisioners][:files] = Dir.glob(File.join(data[:'template-dir'], data[:distribution], 'files', '*'))
|
|
103
|
+
|
|
104
|
+
data[:password] = password
|
|
105
|
+
logger.debug("Temporary password: '#{data[:password]}'")
|
|
106
|
+
|
|
107
|
+
data[:identifier] = replace_needles(data[:identifier])
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
# Choose_version is a method that selects required version from available versions.
|
|
111
|
+
def choose_version
|
|
112
|
+
version = data[:version]
|
|
113
|
+
|
|
114
|
+
available_versions = []
|
|
115
|
+
data[:distro]['versions'].each do |v|
|
|
116
|
+
available_versions << { major: v['major_version'].to_i, minor: v['minor_version'].to_i, patch: v['patch_version'].to_i, version: v }
|
|
117
|
+
end
|
|
118
|
+
available_versions.sort_by! { |v| [v[:major], v[:minor], v[:patch]] }.reverse!
|
|
119
|
+
|
|
120
|
+
return available_versions.first[:version] if version == :newest
|
|
121
|
+
|
|
122
|
+
version_parts = version.split('.')
|
|
123
|
+
fail Comfy::Errors::InvalidDistributionVersionError, "Version '#{version}' is not a valid distribution version" if version_parts.size > 3
|
|
124
|
+
|
|
125
|
+
version_parts.map! do |part|
|
|
126
|
+
fail Comfy::Errors::InvalidDistributionVersionError, "Version '#{version}' is not a valid distribution version" unless part =~ /\A\d+\z/
|
|
127
|
+
|
|
128
|
+
part.to_i
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
selected = available_versions.select { |v| v[:major] == version_parts[0] }
|
|
132
|
+
if version_parts.size > 1
|
|
133
|
+
selected = selected.select { |v| v[:minor] == version_parts[1] }
|
|
134
|
+
|
|
135
|
+
if version_parts.size > 2
|
|
136
|
+
selected = selected.select { |v| v[:patch] == version_parts[2] }
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
fail Comfy::Errors::NoSuchDistributionVersionError, "No version '#{version}' available for distribution '#{data[:distribution]}'" if selected.empty?
|
|
141
|
+
|
|
142
|
+
selected.sort_by { |v| [v[:major], v[:minor], v[:patch]] }.reverse.first[:version]
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
# Method generating a temporary random password used while creating image.
|
|
146
|
+
#
|
|
147
|
+
# @return [String] password
|
|
148
|
+
def password
|
|
149
|
+
o = [('a'..'z'), ('A'..'Z')].map(&:to_a).flatten
|
|
150
|
+
(0...100).map { o[rand(o.length)] }.join
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
# Description returns cloud appliance descriptor JSON. It uses information gathered from command line arguments
|
|
154
|
+
# and the config file.
|
|
155
|
+
#
|
|
156
|
+
# @param builder [Symbol] builder used in the description of the cloud appliance descriptor
|
|
157
|
+
#
|
|
158
|
+
# @return [Json] appliance descriptor in Json format
|
|
159
|
+
def description(builder)
|
|
160
|
+
# FIXME? mapping platforms/builders to formats is hardcoded for now, nothing else is supported
|
|
161
|
+
formats = { 'virtualbox' => 'ova', 'qemu' => 'qcow2' }
|
|
162
|
+
vm_dir = "comfy_#{data[:distribution]}-#{data[:distro][:version]['major_version']}.#{data[:distro][:version]['minor_version']}_#{builder}"
|
|
163
|
+
vm_name = "#{vm_dir}.#{formats[builder]}"
|
|
164
|
+
disk_path = File.join(data[:'output-dir'],vm_dir,vm_name)
|
|
165
|
+
|
|
166
|
+
os = Cloud::Appliance::Descriptor::Os.new distribution: data[:distribution], version: version_string
|
|
167
|
+
disk = Cloud::Appliance::Descriptor::Disk.new type: :os, format: formats[builder], path: disk_path
|
|
168
|
+
|
|
169
|
+
appliance = Cloud::Appliance::Descriptor::Appliance.new action: :registration, os: os, disks: [disk]
|
|
170
|
+
appliance.title = data[:distro]['name']
|
|
171
|
+
appliance.identifier = data[:identifier]
|
|
172
|
+
appliance.version = Time.new.strftime(TIMESTAMP_FORMAT)
|
|
173
|
+
appliance.groups = data[:groups]
|
|
174
|
+
|
|
175
|
+
appliance.to_json
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
# Replace needles in the argument.
|
|
179
|
+
# Replacements are picked from NEEDLE_REPLACEMENTS constant.
|
|
180
|
+
#
|
|
181
|
+
# @param [String] format_string string with needles to be replaced
|
|
182
|
+
#
|
|
183
|
+
# @return [String] format_string with all needles replaced
|
|
184
|
+
def replace_needles(format_string)
|
|
185
|
+
format_string.gsub(REPLACEMENT_REGEX) do |match|
|
|
186
|
+
NEEDLE_REPLACEMENTS.key?(match.to_sym) ? NEEDLE_REPLACEMENTS[match.to_sym].call(self) : match
|
|
187
|
+
end
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
# Simple method used to return the version string
|
|
191
|
+
#
|
|
192
|
+
# @return [String] string which contains major, minor, and patch version (if possible).
|
|
193
|
+
def version_string
|
|
194
|
+
result = []
|
|
195
|
+
result << data[:distro][:version]['major_version']
|
|
196
|
+
result << data[:distro][:version]['minor_version']
|
|
197
|
+
result << data[:distro][:version]['patch_version']
|
|
198
|
+
result.compact.join('.')
|
|
199
|
+
end
|
|
200
|
+
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
class Comfy::Errors::InvalidDistributionVersionError < StandardError; end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
class Comfy::Errors::NoSuchDistributionVersionError < StandardError; end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
class Comfy::Errors::PackerError < StandardError; end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
class Comfy::Errors::PackerExecutionError < Comfy::Errors::PackerError; end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
class Comfy::Errors::PackerValidationError < Comfy::Errors::PackerError; end
|
data/lib/comfy/errors.rb
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
require 'settingslogic'
|
|
2
|
+
|
|
3
|
+
class Comfy::Settings < Settingslogic
|
|
4
|
+
CONFIGURATION = 'comfy.yml'
|
|
5
|
+
|
|
6
|
+
# three possible configuration file locations in order by preference
|
|
7
|
+
# if configuration file is found rest of the locations are ignored
|
|
8
|
+
source "#{ENV['HOME']}/.comfy/#{CONFIGURATION}"\
|
|
9
|
+
if File.exist?("#{ENV['HOME']}/.comfy/#{CONFIGURATION}")
|
|
10
|
+
source "/etc/comfy/#{CONFIGURATION}"\
|
|
11
|
+
if File.exist?("/etc/comfy/#{CONFIGURATION}")
|
|
12
|
+
source "#{File.dirname(__FILE__)}/../../config/#{CONFIGURATION}"
|
|
13
|
+
|
|
14
|
+
namespace 'production'
|
|
15
|
+
end
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
require 'tempfile'
|
|
2
|
+
require 'erb'
|
|
3
|
+
require 'fileutils'
|
|
4
|
+
require 'tmpdir'
|
|
5
|
+
|
|
6
|
+
# Class used for preparing and filling file templates.
|
|
7
|
+
class Comfy::Templater
|
|
8
|
+
attr_reader :data
|
|
9
|
+
|
|
10
|
+
# Creates an instance of Templater.
|
|
11
|
+
#
|
|
12
|
+
# @param data [Hash] prepared data with distro, provisioners, files, password and identifier info.
|
|
13
|
+
def initialize(data)
|
|
14
|
+
@data = data
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# Prepares *.json and *.cfg files from templates for selected distribution
|
|
18
|
+
def prepare_files
|
|
19
|
+
prepare_file('cfg')
|
|
20
|
+
prepare_file('packer', true)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
private
|
|
24
|
+
|
|
25
|
+
# Method prepares .erb file with given data.
|
|
26
|
+
#
|
|
27
|
+
# @param name [String] type of file for preparation.
|
|
28
|
+
# @param packer [Boolean] (implicite value = false).
|
|
29
|
+
def prepare_file(name, packer = false)
|
|
30
|
+
logger.debug("Creating temporary #{name} file...")
|
|
31
|
+
tmp = Tempfile.new("comfy_#{name}")
|
|
32
|
+
logger.debug("Temporary file '#{tmp.path}' was created.")
|
|
33
|
+
|
|
34
|
+
output = File.join(data[:server_dir], "#{data[:distribution]}.#{name}")
|
|
35
|
+
|
|
36
|
+
logger.debug("Writing to temporary #{name} file...")
|
|
37
|
+
template_path = File.join(data[:'template-dir'], data[:distribution], "#{data[:distribution]}.#{name}.erb")
|
|
38
|
+
template_path = File.join(data[:'template-dir'], 'packer.erb') if packer
|
|
39
|
+
write_to_tmp(tmp, populate_template(template_path))
|
|
40
|
+
|
|
41
|
+
logger.debug("Copying #{name} file to its proper location...")
|
|
42
|
+
FileUtils.cp(tmp.path, output)
|
|
43
|
+
|
|
44
|
+
logger.debug("Cleaning temporary #{name} file...")
|
|
45
|
+
tmp.close(true)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def write_to_tmp(tmp, data)
|
|
49
|
+
tmp.write(data)
|
|
50
|
+
tmp.flush
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# Actual filling of .erb fils with given info.
|
|
54
|
+
#
|
|
55
|
+
# @param template [String] path to template file.
|
|
56
|
+
def populate_template(template)
|
|
57
|
+
logger.debug("Populating template '#{template}'")
|
|
58
|
+
erb = ERB.new(File.read(template), nil, '-')
|
|
59
|
+
erb.filename = template
|
|
60
|
+
erb.result(binding)
|
|
61
|
+
end
|
|
62
|
+
end
|
data/lib/comfy.rb
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
require 'comfy/settings'
|
|
2
|
+
|
|
3
|
+
module Comfy
|
|
4
|
+
GEM_DIR = File.realdirpath(File.join(File.dirname(__FILE__), '..'))
|
|
5
|
+
DESCRIPTION_SCHEMA_FILE = File.join(GEM_DIR, 'schema', 'distribution_descriptor.schema')
|
|
6
|
+
TEMPLATE_DIR = Comfy::Settings['template-dir'] || File.join(GEM_DIR, 'lib', 'templates')
|
|
7
|
+
PACKER_FILE = File.join(TEMPLATE_DIR, 'packer.erb')
|
|
8
|
+
|
|
9
|
+
require 'active_support/all'
|
|
10
|
+
|
|
11
|
+
require 'comfy/extensions/yell'
|
|
12
|
+
|
|
13
|
+
require 'comfy/command_executioner'
|
|
14
|
+
require 'comfy/version'
|
|
15
|
+
require 'comfy/templater'
|
|
16
|
+
require 'comfy/creator'
|
|
17
|
+
require 'comfy/errors'
|
|
18
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
### Kickstart
|
|
2
|
+
## Fresh install, not an upgrade
|
|
3
|
+
install
|
|
4
|
+
url --url=http://mirror.nextlayer.at/centos/<%= @data[:distro][:version]['major_version'] %>.<%= @data[:distro][:version]['minor_version'] %>.<%= @data[:distro][:version]['patch_version'] %>/os/x86_64/
|
|
5
|
+
lang en_US.UTF-8
|
|
6
|
+
keyboard us
|
|
7
|
+
timezone UTC
|
|
8
|
+
## Disk Partitioning - how the boot loader should be installed, delete all partitions/mbr, then create
|
|
9
|
+
bootloader --location=mbr
|
|
10
|
+
zerombr
|
|
11
|
+
clearpart --all --initlabel
|
|
12
|
+
part / --size=1 --grow --fstype ext4
|
|
13
|
+
## Don't use GUI
|
|
14
|
+
text
|
|
15
|
+
## Don't configure X
|
|
16
|
+
skipx
|
|
17
|
+
## Firstboot - the druid that helps you to set up the system after install - disabled
|
|
18
|
+
firstboot --disabled
|
|
19
|
+
## Authentication
|
|
20
|
+
## Sets up the authentication options - use shadow passwords, encryption for user passwords
|
|
21
|
+
authconfig --enableshadow --passalgo=sha512
|
|
22
|
+
auth --useshadow --enablemd5
|
|
23
|
+
## Sets the system's root password
|
|
24
|
+
rootpw <%= @data[:password] %>
|
|
25
|
+
## Configure NICs - use dhcp - disable IPv6
|
|
26
|
+
network --device=eth0 --bootproto dhcp --onboot=yes --noipv6
|
|
27
|
+
network --device=eth1 --bootproto dhcp --onboot=yes --noipv6
|
|
28
|
+
## Firewall - enable and open ssh port
|
|
29
|
+
firewall --enabled --service=ssh
|
|
30
|
+
## Selinux - disable
|
|
31
|
+
selinux --disabled
|
|
32
|
+
## Reboot the machine after the install
|
|
33
|
+
reboot
|
|
34
|
+
%packages --nobase
|
|
35
|
+
## Add basic packages groups
|
|
36
|
+
@core
|
|
37
|
+
## Add basic packages
|
|
38
|
+
wget
|
|
39
|
+
curl
|
|
40
|
+
bzip2
|
|
41
|
+
## Add extra packages
|
|
42
|
+
openssh-clients
|
|
43
|
+
openssh-server
|
|
44
|
+
%end
|
|
45
|
+
%post
|
|
46
|
+
/usr/bin/yum -y install sudo
|
|
47
|
+
%end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "CentOS",
|
|
3
|
+
"versions": [{
|
|
4
|
+
"major_version": "7",
|
|
5
|
+
"minor_version": "1",
|
|
6
|
+
"patch_version": "1503",
|
|
7
|
+
"iso_url": "http://merlin.fit.vutbr.cz/mirrors/centos/7/isos/x86_64/CentOS-7-x86_64-NetInstall-1503.iso",
|
|
8
|
+
"iso_checksum": "498bb78789ddc7973fe14358822eb1b48521bbaca91c17bd132c7f8c903d79b3"
|
|
9
|
+
}],
|
|
10
|
+
"boot_command": "linux ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}",
|
|
11
|
+
"qemu": {
|
|
12
|
+
"accelerator": "kvm",
|
|
13
|
+
"qemuargs": [ [ "-m", "1024M" ] ]
|
|
14
|
+
},
|
|
15
|
+
"virtualbox": {
|
|
16
|
+
"guest_os_type": "RedHat_64",
|
|
17
|
+
"vboxmanage": [ ["modifyvm", "{{.Name}}", "--memory", "1024"] ],
|
|
18
|
+
"guest_additions_mode": "disable"
|
|
19
|
+
}
|
|
20
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# If this is set, 'root' will not be able to ssh in and they
|
|
2
|
+
# will get a message to login instead as the above $user (ubuntu)
|
|
3
|
+
disable_root: False
|
|
4
|
+
user: root
|
|
5
|
+
ssh_pwauth: False
|
|
6
|
+
ssh_deletekeys: True
|
|
7
|
+
ssh_genkeytypes: ['rsa', 'dsa']
|
|
8
|
+
ssh_svcname: sshd
|
|
9
|
+
|
|
10
|
+
# This will cause the set+update hostname module to not operate (if true)
|
|
11
|
+
preserve_hostname: false
|
|
12
|
+
cc_ready_cmd: ['/bin/true']
|
|
13
|
+
mount_default_fields: [~, ~, 'auto', 'defaults,nofail', '0', '2']
|
|
14
|
+
syslog_fix_perms: ~
|
|
15
|
+
manage_etc_hosts: True
|
|
16
|
+
|
|
17
|
+
# Update and upgrade system on first boot
|
|
18
|
+
apt_preserve_sources_list: True
|
|
19
|
+
package_update: True
|
|
20
|
+
package_upgrade: True
|
|
21
|
+
package_reboot_if_required: True
|
|
22
|
+
|
|
23
|
+
# work only with OpenNebula, use network based datasource,
|
|
24
|
+
# so that we can successfully resolve IPv4 based hostname
|
|
25
|
+
disable_ec2_metadata: True
|
|
26
|
+
datasource_list: ['OpenNebula']
|
|
27
|
+
datasource:
|
|
28
|
+
OpenNebula:
|
|
29
|
+
dsmode: net
|
|
30
|
+
|
|
31
|
+
# The modules that run in the 'init' stage
|
|
32
|
+
cloud_init_modules:
|
|
33
|
+
- migrator
|
|
34
|
+
- seed_random
|
|
35
|
+
- bootcmd
|
|
36
|
+
- write-files
|
|
37
|
+
- growpart
|
|
38
|
+
- resizefs
|
|
39
|
+
- set_hostname
|
|
40
|
+
- update_hostname
|
|
41
|
+
- update_etc_hosts
|
|
42
|
+
- ca-certs
|
|
43
|
+
- rsyslog
|
|
44
|
+
- users-groups
|
|
45
|
+
- ssh
|
|
46
|
+
|
|
47
|
+
# The modules that run in the 'config' stage
|
|
48
|
+
cloud_config_modules:
|
|
49
|
+
# Emit the cloud config ready event
|
|
50
|
+
# this can be used by upstart jobs for 'start on cloud-config'.
|
|
51
|
+
- emit_upstart
|
|
52
|
+
- disk_setup
|
|
53
|
+
- mounts
|
|
54
|
+
- ssh-import-id
|
|
55
|
+
- locale
|
|
56
|
+
- set-passwords
|
|
57
|
+
- grub-dpkg
|
|
58
|
+
- apt-pipelining
|
|
59
|
+
- apt-configure
|
|
60
|
+
- package-update-upgrade-install
|
|
61
|
+
- landscape
|
|
62
|
+
- timezone
|
|
63
|
+
- puppet
|
|
64
|
+
- chef
|
|
65
|
+
- salt-minion
|
|
66
|
+
- mcollective
|
|
67
|
+
- disable-ec2-metadata
|
|
68
|
+
- runcmd
|
|
69
|
+
- byobu
|
|
70
|
+
|
|
71
|
+
# The modules that run in the 'final' stage
|
|
72
|
+
cloud_final_modules:
|
|
73
|
+
- rightscale_userdata
|
|
74
|
+
- scripts-per-once
|
|
75
|
+
- scripts-per-boot
|
|
76
|
+
- scripts-per-instance
|
|
77
|
+
- scripts-user
|
|
78
|
+
- ssh-authkey-fingerprints
|
|
79
|
+
- keys-to-console
|
|
80
|
+
- phone-home
|
|
81
|
+
- final-message
|
|
82
|
+
- power-state-change
|
|
83
|
+
|
|
84
|
+
# System and/or distro specific settings
|
|
85
|
+
# (not accessible to handlers/transforms)
|
|
86
|
+
system_info:
|
|
87
|
+
# This will affect which distro class gets used
|
|
88
|
+
distro: rhel
|
|
89
|
+
# Other config here will be given to the distro class and/or path classes
|
|
90
|
+
paths:
|
|
91
|
+
cloud_dir: /var/lib/cloud/
|
|
92
|
+
templates_dir: /etc/cloud/templates/
|
|
93
|
+
upstart_dir: /etc/init/
|
|
94
|
+
package_mirrors:
|
|
95
|
+
- arches: [default]
|
|
96
|
+
failsafe:
|
|
97
|
+
primary: http://http.us.debian.org/debian/
|
|
98
|
+
security: http://security.debian.org/
|
|
99
|
+
ssh_svcname: sshd
|
|
100
|
+
|
|
101
|
+
# vim:syntax=yaml
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# This file is part of systemd.
|
|
2
|
+
#
|
|
3
|
+
# systemd is free software; you can redistribute it and/or modify it
|
|
4
|
+
# under the terms of the GNU Lesser General Public License as published by
|
|
5
|
+
# the Free Software Foundation; either version 2.1 of the License, or
|
|
6
|
+
# (at your option) any later version.
|
|
7
|
+
|
|
8
|
+
[Unit]
|
|
9
|
+
Description=Getty on %I
|
|
10
|
+
Documentation=man:agetty(8) man:systemd-getty-generator(8)
|
|
11
|
+
Documentation=http://0pointer.de/blog/projects/serial-console.html
|
|
12
|
+
After=systemd-user-sessions.service plymouth-quit-wait.service
|
|
13
|
+
After=rc-local.service
|
|
14
|
+
|
|
15
|
+
# If additional gettys are spawned during boot then we should make
|
|
16
|
+
# sure that this is synchronized before getty.target, even though
|
|
17
|
+
# getty.target didn't actually pull it in.
|
|
18
|
+
Before=getty.target
|
|
19
|
+
IgnoreOnIsolate=yes
|
|
20
|
+
|
|
21
|
+
# On systems without virtual consoles, don't start any getty. Note
|
|
22
|
+
# that serial gettys are covered by serial-getty@.service, not this
|
|
23
|
+
# unit.
|
|
24
|
+
ConditionPathExists=/dev/tty0
|
|
25
|
+
|
|
26
|
+
[Service]
|
|
27
|
+
# the VT is cleared by TTYVTDisallocate
|
|
28
|
+
ExecStart=-/sbin/agetty --autologin root --noclear %I $TERM
|
|
29
|
+
Type=idle
|
|
30
|
+
Restart=always
|
|
31
|
+
RestartSec=0
|
|
32
|
+
UtmpIdentifier=%I
|
|
33
|
+
TTYPath=/dev/%I
|
|
34
|
+
TTYReset=yes
|
|
35
|
+
TTYVHangup=yes
|
|
36
|
+
TTYVTDisallocate=yes
|
|
37
|
+
KillMode=process
|
|
38
|
+
IgnoreSIGPIPE=no
|
|
39
|
+
SendSIGHUP=yes
|
|
40
|
+
|
|
41
|
+
# Unset locale for the console getty since the console has problems
|
|
42
|
+
# displaying some internationalized messages.
|
|
43
|
+
Environment=LANG= LANGUAGE= LC_CTYPE= LC_NUMERIC= LC_TIME= LC_COLLATE= LC_MONETARY= LC_MESSAGES= LC_PAPER= LC_NAME= LC_ADDRESS= LC_TELEPHONE= LC_MEASUREMENT= LC_IDENTIFICATION=
|
|
44
|
+
|
|
45
|
+
[Install]
|
|
46
|
+
WantedBy=getty.target
|
|
47
|
+
Alias=getty@ttys0.service
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
GRUB_TIMEOUT=5
|
|
2
|
+
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
|
|
3
|
+
GRUB_DEFAULT=saved
|
|
4
|
+
GRUB_DISABLE_SUBMENU=true
|
|
5
|
+
GRUB_TERMINAL_OUTPUT="console"
|
|
6
|
+
GRUB_CMDLINE_LINUX="vconsole.keymap=us crashkernel=auto vconsole.font=latarcyrheb-sun16 rhgb quiet net.ifnames=0 biosdevname=0 console=ttys0,115200n8 console=tty0"
|
|
7
|
+
#GRUB_CMDLINE_LINUX="console=ttys0,115200n8 console=tty0"
|
|
8
|
+
GRUB_DISABLE_RECOVERY="true"
|
|
9
|
+
GRUB_TERMINAL="serial"
|
|
10
|
+
GRUB_SERIAL_COMMAND="serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1"
|
|
11
|
+
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
[DEFAULT]
|
|
2
|
+
|
|
3
|
+
# Seznam vygenerovany skriptem /software/meta-admin/scripts/get_nodes_ips
|
|
4
|
+
# Vygeneruje pouze C site, tzn. je tam o nekolik set hostu vic nez ve skutecnosti
|
|
5
|
+
|
|
6
|
+
ignoreip = 127.0.0.1 147.228.1.0/24 147.251.17.0/24 147.228.240.0/24 147.228.241.0/24 147.231.11.0/24 147.231.18.0/24 147.251.11.0/24 147.251.252.0/24 147.251.254.0/24 147.251.3.0/24 147.251.84.0/24 147.251.9.0/24 195.113.0.0/24 195.113.123.0/24 195.113.209.0/24 195.113.214.0/24 78.128.210.0/24
|
|
7
|
+
|
|
8
|
+
[ssh]
|
|
9
|
+
|
|
10
|
+
enabled = true
|
|
11
|
+
port = ssh
|
|
12
|
+
filter = sshd
|
|
13
|
+
logpath = /var/log/auth.log
|
|
14
|
+
maxretry = 100
|
|
15
|
+
findtime = 86400
|
|
16
|
+
bantime = 1209600
|
|
17
|
+
|