Puppet Class: apt

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

Overview

Parameters:

  • purge_sources (Boolean) (defaults to: false)
  • purge_preferences (Boolean) (defaults to: false)
  • use_proxy (Boolean) (defaults to: true)


1
2
3
4
5
6
7
8
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'modules/apt/manifests/init.pp', line 1

class apt(
    Boolean $purge_sources     = false,
    Boolean $purge_preferences = false,
    Boolean $use_proxy         = true,
) {
    exec { 'apt-get update':
        path        => '/usr/bin',
        timeout     => 240,
        returns     => [ 0, 100 ],
        refreshonly => true,
    }

    # Directory to hold the repository signing keys
    file { '/var/lib/apt/keys':
        ensure  => directory,
        owner   => 'root',
        group   => 'root',
        mode    => '0700',
        recurse => true,
        purge   => true,
    }

    # prefer Wikimedia APT repository packages in all cases
    apt::pin { 'wikimedia':
        package  => '*',
        pin      => 'release o=Wikimedia',
        priority => 1001,
    }

    file { '/etc/apt/sources.list.d':
        ensure  => directory,
        owner   => 'root',
        group   => 'root',
        mode    => '0755',
        recurse => $purge_sources,
        purge   => $purge_sources,
    }
    file { '/etc/apt/preferences.d':
        ensure  => directory,
        owner   => 'root',
        group   => 'root',
        mode    => '0755',
        recurse => $purge_preferences,
        purge   => $purge_preferences,
    }

    if $use_proxy {
        $http_proxy = "http://webproxy.${::site}.wmnet:8080"

        if $::operatingsystem == 'Debian' {
            apt::conf { 'security-debian-proxy':
                ensure   => present,
                priority => '80',
                key      => 'Acquire::http::Proxy::security.debian.org',
                value    => $http_proxy,
                before   => File['/etc/apt/apt.conf'],
            }
            apt::conf { 'security-cdn-debian-proxy':
                ensure   => present,
                priority => '80',
                key      => 'Acquire::http::Proxy::security-cdn.debian.org',
                value    => $http_proxy,
                before   => File['/etc/apt/apt.conf']
            }
        } else {
            fail("Unknown operating system '${::operatingsystem}'.")
        }
    }

    if os_version('debian jessie') {
        $components = 'main backports thirdparty'
    } else {
        if $facts['is_virtual'] == false {
            # RAID tools only needed on bare metal servers
            $components = 'main thirdparty/hwraid'
        } else {
            $components = 'main'
        }
    }

    apt::repository { 'wikimedia':
        uri         => 'http://apt.wikimedia.org/wikimedia',
        dist        => "${::lsbdistcodename}-wikimedia",
        components  => $components,
        comment_old => true,
    }

    if os_version('debian >= stretch'){
        apt::repository { 'debian-backports':
            uri         => 'http://mirrors.wikimedia.org/debian/',
            dist        => "${::lsbdistcodename}-backports",
            components  => 'main contrib non-free',
            comment_old => true,
        }
    }

    apt::conf { 'InstallRecommends':
        ensure   => 'present',
        priority => '00',
        key      => 'APT::Install-Recommends',
        value    => false,
        before   => File['/etc/apt/apt.conf'],
    }

    if os_version('debian >= buster') {
        apt::conf { 'apt-harden':
            ensure   => 'present',
            priority => '30',
            key      => 'APT::Sandbox::Seccomp',
            value    => true,
            before   => File['/etc/apt/apt.conf'],
        }
    }

    # 00InstallRecommends already provides this.
    # TODO: remove once merged.
    apt::conf { 'no-recommends':
        ensure   => 'absent',
        priority => '90',
        key      => 'APT::Install-Recommends',
        value    => '0',
        before   => File['/etc/apt/apt.conf'],
    }

    # This will munge /etc/apt/apt.conf that get's created during installation
    # process (either labs vmbuilder or d-i). Given the ones below exist, it is
    # no longer needed after the installation is over
    file { '/etc/apt/apt.conf':
        ensure => absent,
        notify => Exec['apt-get update'],
    }
}