Move debian_mirror over to being a hash
[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         $listen_addresses = Hash(hiera('roles.debian_mirror').map |$h| {
7                 $h.map |$k, $v| { [$k,$v] }[0]
8         }).dig($::fqdn, 'listen-addresses')
9                 .then |$a| { $a + [ '127.0.0.1:80', '[::1]:80' ] }
10                 .lest || { ['*:80'] }
11
12         $vhost_listen = join([
13                 *$listen_addresses,
14                 has_role('bgp') ? {
15                         true => '193.31.7.2:80 [2a02:158:ffff:deb::2]:80',
16                         default => '',
17                 }], ' ')
18         $onion_v4_addr = $::hostname ? {
19                 mirror-bytemark => '5.153.231.45',
20                 klecker    => '130.89.148.12',
21                 mirror-isc => '149.20.4.15',
22                 default    => undef,
23         }
24
25         apache2::site { '010-ftp.debian.org':
26                 site   => 'ftp.debian.org',
27                 content => template('roles/apache-ftp.debian.org.erb'),
28         }
29
30         if has_role('debian_mirror_onion') {
31                 if ! $onion_v4_addr {
32                         fail("Do not have an onion_v4_addr set for $::hostname.")
33                 }
34
35                 onion::service { 'ftp.debian.org':
36                         port => 80,
37                         target_port => 80,
38                         target_address => $onion_v4_addr,
39                 }
40         }
41
42         $mirrors = hiera('roles.debian_mirror', {})
43         $fastly_mirrors = $mirrors.filter |$h| { $h[1]['fastly-backend'] }
44         $hosts_to_check = $fastly_mirrors.map |$h| { $h[1]['service-hostname'] }
45
46         roles::mirror_health { 'ftp':
47                 check_hosts   => $hosts_to_check,
48                 check_service => 'ftp',
49                 url           => 'http://debian.backend.mirrors.debian.org/debian/dists/sid/Release',
50                 health_url    => 'http://debian.backend.mirrors.debian.org/_health',
51         }
52 }