Add sample recipe in documentation
This commit is contained in:
parent
ec8d194ffd
commit
bf760a2c62
101
README.md
101
README.md
@ -219,6 +219,107 @@ design and usage of Domain Specific Languages in Ruby, and refactor
|
|||||||
all my scripts as "recipes" in a common language.
|
all my scripts as "recipes" in a common language.
|
||||||
|
|
||||||
|
|
||||||
|
Sample recipe
|
||||||
|
-------------
|
||||||
|
|
||||||
|
Based on the previous template example (FreeBSD jails.conf
|
||||||
|
template):
|
||||||
|
|
||||||
|
require 'producer/stdlib'
|
||||||
|
|
||||||
|
JAILS_ROOT = '/var/jails'.freeze
|
||||||
|
ZROOT = 'tank/jails'.freeze
|
||||||
|
INTERFACE = 're0'.freeze
|
||||||
|
SETS = {
|
||||||
|
base: '2b028a894d25711ad496762622a52d74b1e32ee04693ad1cf056e3ddcdc23975',
|
||||||
|
src: 'f919287a5ef51d4f133f27c99c54f2e8054f408d3dd53bc60f4e233cc75ec03d'
|
||||||
|
}.freeze
|
||||||
|
JAILS = [
|
||||||
|
{
|
||||||
|
name: 'freebsd-10r1',
|
||||||
|
src: true,
|
||||||
|
addr4: '10.0.0.1'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'freebsd-10r1-gcc',
|
||||||
|
src: true,
|
||||||
|
addr4: '10.0.0.2'
|
||||||
|
}
|
||||||
|
].freeze
|
||||||
|
|
||||||
|
task :freebsd_archives_fetch do
|
||||||
|
SETS.keys.each { |set| condition { no_file? "/tmp/#{set}.txz"} }
|
||||||
|
|
||||||
|
SETS.each do |set, sum|
|
||||||
|
sh <<-eoh
|
||||||
|
cd /tmp && \
|
||||||
|
fetch ftp://ftp.freebsd.org:/pub/FreeBSD/releases/amd64/10.1-RELEASE/#{set}.txz && \
|
||||||
|
sha256 -c #{sum} #{set}.txz
|
||||||
|
eoh
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
task :jails_fs_create do
|
||||||
|
condition { no_sh "zfs list #{ZROOT}" }
|
||||||
|
sh "zfs create -o mountpoint=#{JAILS_ROOT} -o compress=lz4 #{ZROOT}"
|
||||||
|
end
|
||||||
|
|
||||||
|
JAILS.each do |jail|
|
||||||
|
root = "#{JAILS_ROOT}/#{jail[:name]}"
|
||||||
|
fs = "#{ZROOT}/#{jail[:name]}"
|
||||||
|
|
||||||
|
task :jail_initialize do
|
||||||
|
condition { no_sh "zfs list #{fs}@install" }
|
||||||
|
|
||||||
|
task :jail_fs_create do
|
||||||
|
condition { no_sh "zfs list #{fs}" }
|
||||||
|
|
||||||
|
sh "zfs create #{fs}"
|
||||||
|
|
||||||
|
SETS.keys.each do |set|
|
||||||
|
next if set == 'src' && !jail[:src]
|
||||||
|
sh "tar -JxC #{root}/ -f /tmp/#{set}.txz"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
task :rc_conf do
|
||||||
|
file_write_once "#{root}/etc/rc.conf", <<-eoh
|
||||||
|
hostname=#{jail[:name]}
|
||||||
|
# ...
|
||||||
|
eoh
|
||||||
|
end
|
||||||
|
|
||||||
|
task :root_passwd do
|
||||||
|
sh "chroot #{root} pw user mod root -w random"
|
||||||
|
end
|
||||||
|
|
||||||
|
task :mail_aliases do
|
||||||
|
condition { no_file? "#{root}/etc/mail/aliases.db" }
|
||||||
|
|
||||||
|
sh "chroot #{root} make -C /etc/mail aliases"
|
||||||
|
end
|
||||||
|
|
||||||
|
freebsd_update_patch_interactive "#{root}/usr/sbin/freebsd-update"
|
||||||
|
|
||||||
|
task :jail_snapshot_install do
|
||||||
|
sh "zfs snapshot #{fs}@install"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
task :jail_update do
|
||||||
|
condition { no_sh "zfs list #{fs}@update" }
|
||||||
|
|
||||||
|
sh "chroot #{root} freebsd-update fetch install"
|
||||||
|
sh "zfs snapshot #{fs}@update"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
task :jails_conf do
|
||||||
|
conf = template 'freebsd/jail.conf', if: INTERFACE, jails: JAILS
|
||||||
|
file_write_once '/etc/jail.conf', conf
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
Similar or related code and tools
|
Similar or related code and tools
|
||||||
---------------------------------
|
---------------------------------
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user