Puppet Class: lxc

Defined in:
modules/lxc/manifests/init.pp

Overview

SPDX-License-Identifier: Apache-2.0

Class: lxc

Provision LXC

Parameters:

container_root

Directory where LXC will store containers (default: '/srv/lxc')

Parameters:

  • container_root (Stdlib::Unixpath) (defaults to: '/srv/lxc')


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'modules/lxc/manifests/init.pp', line 10

class lxc(
    Stdlib::Unixpath $container_root = '/srv/lxc',
) {
    ensure_packages(['bridge-utils', 'dnsmasq-base', 'redir', 'lxc'])
    ensure_packages(['lxc-templates', 'ebtables', 'iptables', 'libvirt-clients', 'libvirt-daemon-system'])

    exec { 'virsh net-start default':
        command => '/usr/bin/virsh net-start default',
        unless  => "/usr/bin/virsh -q net-list --all|/bin/grep -Eq '^\s*default\s+active'",
        require => Package['ebtables', 'iptables', 'libvirt-clients', 'libvirt-daemon-system'],
    }

    exec { 'virsh net-autostart default':
        command => '/usr/bin/virsh net-autostart default',
        creates => '/etc/libvirt/qemu/networks/autostart/default.xml',
        require => Package['ebtables', 'iptables', 'libvirt-clients', 'libvirt-daemon-system'],
    }

    file { '/etc/lxc/default.conf':
        ensure  => 'present',
        owner   => 'root',
        group   => 'root',
        mode    => '0444',
        source  => "puppet:///modules/lxc/${::lsbdistcodename}/etc-lxc-default.conf",
        require => Package['lxc'],
        notify  => Service['lxc-net'],
    }

    file { '/etc/default/lxc-net':
        ensure  => 'present',
        owner   => 'root',
        group   => 'root',
        mode    => '0444',
        content => 'USE_LXC_BRIDGE="true"',
        require => Package['lxc'],
        notify  => Service['lxc-net'],
    }

    service { 'lxc-net':
        ensure => 'running',
    }

    file { $container_root:
        ensure => 'directory',
        owner  => 'root',
        group  => 'root',
        mode   => '0755',
    }

    if $container_root != '/var/lib/lxc' {
        # Symlink default LXC container storage directory to configured
        # location
        file { '/var/lib/lxc':
            ensure => 'link',
            target => $container_root,
            force  => true,
        }
    }
}