30 lines
791 B
Ruby
Executable File
30 lines
791 B
Ruby
Executable File
#!/usr/bin/env ruby
|
|
|
|
require "optparse"
|
|
|
|
def sh(cmd, *args)
|
|
puts "$ #{cmd} " + args.map {|a| "'#{a}'" }.join(" ")
|
|
system(cmd, *args) or abort "command failed"
|
|
end
|
|
|
|
options = {}
|
|
OptionParser.new do |opts|
|
|
opts.banner = "Usage: lxc-create-container [options]"
|
|
opts.on("-nNAME", "--name=NAME", "container name") do |n|
|
|
options[:name] = n
|
|
end
|
|
end.parse!
|
|
|
|
unless options[:name]
|
|
$stderr.puts "no option for --name supplied"
|
|
exit(1)
|
|
end
|
|
|
|
sh("systemctl", "stop", "lxc-base")
|
|
sh("/run/current-system/sw/bin/lxc-copy", "-n", "base", "-B", "zfs", "-N", options[:name])
|
|
puts "$ cd /etc/nixos/ansible"
|
|
Dir.chdir("/etc/nixos/ansible") do
|
|
sh("nix-shell", "--command", "ansible-playbook -i inventory site.yml --limit #{options[:name]}")
|
|
end
|
|
sh("lxc-info", "--name", "#{options[:name]}")
|