Puppet Class: lxc

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

Overview

Class: lxc

Provision LXC

Parameters:

container_root

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

Parameters:

  • container_root (Any) (defaults to: '/srv/lxc')


9
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'modules/lxc/manifests/init.pp', line 9

class lxc(
    $container_root = '/srv/lxc',
) {
    package { [
        'bridge-utils',
        'dnsmasq-base',
        'redir',
    ]:
        ensure => present,
    }

    package { 'lxc':
        ensure => present,
    }

    if os_version('debian >= buster') {
        package { 'lxc-templates':
            ensure => present,
        }

        require_package(
            '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'],
                Package['iptables'],
                Package['libvirt-clients'],
                Package['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'],
                Package['iptables'],
                Package['libvirt-clients'],
                Package['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,
        }
    }
}