define virtual::vserver::instance( $in_domain, $context, $legacy = false, $distro = 'jessie', $debootstrap_mirror = 'http://cdn.debian.net/debian', $hostname = false, $interface = false, $memory_limit = false ) { $vs_name = $legacy ? { true => $name, false => $in_domain ? { '' => $name, default => "${name}.${in_domain}" } } $vs_hostname = $hostname ? { false => 'none', default => $hostname } $vs_interface = $interface ? { false => 'none', default => $interface } case $vs_name { '': { fail ( "Cannot create VServer with empty name" ) } } case $legacy { true: { exec { "/bin/false # cannot create legacy vserver ${vs_name}": creates => "/etc/vservers/${vs_name}", alias => "vserver_instance_${vs_name}" } } false: { exec { "/usr/local/bin/build_vserver \"${vs_name}\" ${context} ${distro} ${debootstrap_mirror} ${vs_hostname} ${vs_interface} ${memory_limit}": creates => "/etc/vservers/${vs_name}", require => File["/usr/local/bin/build_vserver", "/etc/vservers/.defaults/vdirbase"], alias => "vserver_instance_${vs_name}", # TODO: change when this is fixed: http://projects.puppetlabs.com/issues/4769 timeout => $lsbdistcodename ? { "squeeze" => '31536000', # 1 year default => '-1', }, } } } file { "/etc/vservers/${vs_name}/rlimits": ensure => directory, mode => 0755, owner => root, group => root, require => Exec["vserver_instance_${vs_name}"], } file { "/etc/vservers/${vs_name}/rlimits/rss.hard": mode => 0644, owner => root, group => root, content => template("virtual/rss.hard.erb"), require => $memory_limit ? { false => undef, default => File["/etc/vservers/${vs_name}/rlimits"], }, ensure => $memory_limit ? { false => absent, default => present, }, } file { "/etc/vservers/${vs_name}/rlimits/rss.soft": mode => 0644, owner => root, group => root, content => template("virtual/rss.soft.erb"), require => $memory_limit ? { false => undef, default => File["/etc/vservers/${vs_name}/rlimits"], }, ensure => $memory_limit ? { false => absent, default => present, }, } virtual::vserver::cflags { "${vs_name}-virt_mem": vserver => $vs_name, flag => "virt_mem", ensure => present, require => $memory_limit ? { false => undef, default => Exec["vserver_instance_${vs_name}"], }, ensure => $memory_limit ? { false => absent, default => present, }, } }