lib/vagabond/cookbooks/vagabond/recipes/default.rb in vagabond-0.1.4 vs lib/vagabond/cookbooks/vagabond/recipes/default.rb in vagabond-0.2.0

- old
+ new

@@ -1,10 +1,25 @@ -include_recipe 'lxc::install_dependencies' +include_recipe 'lxc' -cookbook_file '/usr/share/lxc/templates/lxc-centos' do - source 'lxc-centos' - mode 0755 +ruby_block 'LXC template: lxc-centos' do + block do + dir = %w(/usr/share /usr/lib).map do |prefix| + if(File.directory?(d = File.join(prefix, 'lxc/templates'))) + d + end + end.compact.first + raise 'Failed to locate LXC template directory' unless dir + cfl = Chef::Resource::CookbookFile.new( + ::File.join(dir, 'lxc-centos'), + run_context + ) + cfl.source 'lxc-centos' + cfl.mode 0755 + cfl.cookbook cookbook_name.to_s + cfl.action :nothing + cfl.run_action(:create) + end end node[:vagabond][:bases].each do |name, options| next unless options[:enabled] @@ -12,13 +27,13 @@ pkg_coms = [ 'update -y -q', 'upgrade -y -q', 'install curl -y -q' ] - if(%w(debian ubuntu).include?(options[:template])) + if(!options[:template].scan(%r{debian|ubuntu}).empty?) pkg_man = 'apt-get' - elsif(%w(fedora centos).include?(options[:template])) + elsif(!options[:template].scan(%r{fedora|centos}).empty?) pkg_man = 'yum' end if(pkg_man) pkg_coms.map! do |c| "#{pkg_man} #{c}" @@ -38,17 +53,25 @@ 'rm -f /etc/sysctl.d/10-kernel-hardening.conf' ] + pkg_coms + [ 'curl -L https://www.opscode.com/chef/install.sh | bash' ] end +end +node[:vagabond][:customs].each do |name, options| + + lxc_container name do + action :clone + base_container options[:base] + end + if(options[:memory]) lxc_config name do cgroup( - 'memory.limit_in_bytes' => options[:memory][:maximum_ram], + 'memory.limit_in_bytes' => options[:memory][:ram], 'memory.memsw.limit_in_bytes' => ( - Vagabond.get_bytes(options[:memory][:maximum_ram]) + - Vagabond.get_bytes(options[:memory][:maximum_swap]) + Vagabond.get_bytes(options[:memory][:ram]) + + Vagabond.get_bytes(options[:memory][:swap]) ) ) end end end