Store the list of installed packages into a puppet fact
[mirror/dsa-puppet.git] / modules / debian_org / manifests / apt.pp
1 # == Class: debian_org
2 #
3 # Stuff common to all debian.org servers
4 #
5 class debian_org::apt {
6         if versioncmp($::lsbmajdistrelease, '8') <= 0 {
7                 $fallbackmirror = 'http://cdn-fastly.deb.debian.org/debian/'
8         } else {
9                 $fallbackmirror = 'http://deb.debian.org/debian/'
10         }
11
12         if getfromhash($site::nodeinfo, 'hoster', 'mirror-debian') {
13                 $mirror = [ getfromhash($site::nodeinfo, 'hoster', 'mirror-debian'), $fallbackmirror ]
14         } else {
15                 $mirror = [ $fallbackmirror ]
16         }
17
18         # jessie
19         if versioncmp($::lsbmajdistrelease, '8') <= 0 {
20                 site::aptrepo { 'debian':
21                         url        => $mirror,
22                         suite      => [ $::lsbdistcodename ],
23                         components => ['main','contrib','non-free']
24                 }
25         # stretch or buster
26         } else {
27                 site::aptrepo { 'debian':
28                         url        => $mirror,
29                         suite      => [ $::lsbdistcodename, "${::lsbdistcodename}-backports", "${::lsbdistcodename}-updates" ],
30                         components => ['main','contrib','non-free']
31                 }
32         }
33
34         if versioncmp($::lsbmajdistrelease, '8') <= 0 {
35                 site::aptrepo { 'security':
36                         url        => [ 'http://security-cdn.debian.org/', 'http://security.debian.org/' ],
37                         suite      => "${::lsbdistcodename}/updates",
38                         components => ['main','contrib','non-free']
39                 }
40         } else {
41                 site::aptrepo { 'security':
42                         url        => [ 'http://security.debian.org/' ],
43                         suite      => "${::lsbdistcodename}/updates",
44                         components => ['main','contrib','non-free']
45                 }
46         }
47
48         # ca-certificates is installed by the ssl module
49         if versioncmp($::lsbmajdistrelease, '9') <= 0 {
50                 package { 'apt-transport-https':
51                         ensure => installed,
52                 }
53         } else {
54                 # transitional package in buster
55                 package { 'apt-transport-https':
56                         ensure => purged,
57                 }
58         }
59         $dbdosuites = [ 'debian-all', $::lsbdistcodename ]
60         site::aptrepo { 'db.debian.org':
61                 url        => 'https://db.debian.org/debian-admin',
62                 suite      => $dbdosuites,
63                 components => 'main',
64                 key        => 'puppet:///modules/debian_org/db.debian.org.gpg',
65         }
66
67         if ($::hostname in []) {
68                 site::aptrepo { 'proposed-updates':
69                         url        => $mirror,
70                         suite      => "${::lsbdistcodename}-proposed-updates",
71                         components => ['main','contrib','non-free']
72                 }
73         } else {
74                 site::aptrepo { 'proposed-updates':
75                         ensure => absent,
76                 }
77         }
78
79         site::aptrepo { 'debian-cdn':
80                 ensure => absent,
81         }
82         site::aptrepo { 'debian.org':
83                 ensure => absent,
84         }
85         site::aptrepo { 'debian2':
86                 ensure => absent,
87         }
88         site::aptrepo { 'backports2.debian.org':
89                 ensure => absent,
90         }
91         site::aptrepo { 'backports.debian.org':
92                 ensure => absent,
93         }
94         site::aptrepo { 'volatile':
95                 ensure => absent,
96         }
97         site::aptrepo { 'db.debian.org-suite':
98                 ensure => absent,
99         }
100         site::aptrepo { 'debian-lts':
101                 ensure => absent,
102         }
103
104
105
106
107         file { '/etc/apt/trusted-keys.d':
108                 ensure => absent,
109                 force  => true,
110         }
111
112         file { '/etc/apt/trusted.gpg':
113                 mode    => '0600',
114                 content => "",
115         }
116
117         file { '/etc/apt/preferences':
118                 source => 'puppet:///modules/debian_org/apt.preferences',
119         }
120         file { '/etc/apt/apt.conf.d/local-compression':
121                 source => 'puppet:///modules/debian_org/apt.conf.d/local-compression',
122         }
123         file { '/etc/apt/apt.conf.d/local-recommends':
124                 source => 'puppet:///modules/debian_org/apt.conf.d/local-recommends',
125         }
126         file { '/etc/apt/apt.conf.d/local-pdiffs':
127                 source => 'puppet:///modules/debian_org/apt.conf.d/local-pdiffs',
128         }
129         file { '/etc/apt/apt.conf.d/local-langs':
130                 source => 'puppet:///modules/debian_org/apt.conf.d/local-langs',
131         }
132         file { '/etc/apt/apt.conf.d/local-cainfo':
133                 source => 'puppet:///modules/debian_org/apt.conf.d/local-cainfo',
134         }
135         file { '/etc/apt/apt.conf.d/local-pkglist':
136                 source => 'puppet:///modules/debian_org/apt.conf.d/local-pkglist',
137         }
138
139         exec { 'dpkg list':
140                 command => 'dpkg-query -W -f \'${Package}\n\' > /var/lib/misc/thishost/pkglist',
141                 creates => '/var/lib/misc/thishost/pkglist',
142         }
143
144         exec { 'apt-get update':
145                 path    => '/usr/bin:/usr/sbin:/bin:/sbin',
146                 onlyif  => '/usr/local/bin/check_for_updates',
147                 require => File['/usr/local/bin/check_for_updates']
148         }
149         Exec['apt-get update']->Package<| tag == extra_repo |>
150 }