cdd2de944303816d17c87b50a34da091b3151d61
[mirror/dsa-puppet.git] / modules / roles / manifests / debian_mirror.pp
1 class roles::debian_mirror {
2         include roles::archvsync_base
3
4         $mirror_basedir_prefix = hiera('role_config__mirrors.mirror_basedir_prefix')
5         $archive_root = "${mirror_basedir_prefix}debian"
6
7         $vhost_listen = join([
8                 hiera("roles.debian_mirror.${::hostname}.listen-addresses", 'missing') ? {
9                         'missing' => '*:80',
10                         default => join([hiera("roles.debian_mirror.${::hostname}.listen-addresses"), '127.0.0.1:80', '[::1]:80'])
11                 },
12                 has_role('bgp') ? {
13                         true => '193.31.7.2:80 [2a02:158:ffff:deb::2]:80',
14                         default => '',
15                 }], ' ')
16         $onion_v4_addr = $::hostname ? {
17                 mirror-bytemark => '5.153.231.45',
18                 klecker    => '130.89.148.12',
19                 mirror-isc => '149.20.4.15',
20                 default    => undef,
21         }
22
23         apache2::site { '010-ftp.debian.org':
24                 site   => 'ftp.debian.org',
25                 content => template('roles/apache-ftp.debian.org.erb'),
26         }
27
28         if has_role('debian_mirror_onion') {
29                 if ! $onion_v4_addr {
30                         fail("Do not have an onion_v4_addr set for $::hostname.")
31                 }
32
33                 onion::service { 'ftp.debian.org':
34                         port => 80,
35                         target_port => 80,
36                         target_address => $onion_v4_addr,
37                 }
38         }
39
40         # roles is a list of hashes, which needs to be unpacked into a regular hash
41         $mirrors = hiera('roles.debian_mirror', [])
42         # unpack $mirrors and construct a hash
43         $m2 = Hash($mirrors.map |$h| { $h.map |$k, $v| { [$k, $v] }[0]})
44         $fastly_mirrors = $m2.filter |$h| { $h[1]['fastly-backend'] }
45         $hosts_to_check = $fastly_mirrors.map |$h| { $h[1]['service-hostname'] }
46
47         roles::mirror_health { 'ftp':
48                 check_hosts   => $hosts_to_check,
49                 check_service => 'ftp',
50                 url           => 'http://debian.backend.mirrors.debian.org/debian/dists/sid/Release',
51                 health_url    => 'http://debian.backend.mirrors.debian.org/_health',
52         }
53 }