debian_mirror -> hiera role
[mirror/dsa-puppet.git] / modules / roles / manifests / debian_mirror.pp
index c0b17b3..45f6480 100644 (file)
@@ -1,55 +1,51 @@
-class roles::debian_mirror {
-       include roles::archvsync_base
+# an ftp.debian.org mirror/cdn backend
+#
+# @param listen_addr IP addresses to have apache listen on
+# @param onion_service provide the onion service from this host
+# @param healthcheck_name name to access this node in the health checker
+class roles::debian_mirror(
+  Array[Stdlib::IP::Address] $listen_addr = [],
+  Boolean $onion_service = false,
+  Optional[String] $healthcheck_name = undef,
+) {
+  include roles::archvsync_base
+  include apache2
 
-       $mirror_basedir_prefix = hiera('role_config__mirrors.mirror_basedir_prefix')
-       $archive_root = "${mirror_basedir_prefix}debian"
-        $listen_addresses = Hash(hiera('roles.debian_mirror').map |$h| {
-                $h.map |$k, $v| { [$k,$v] }[0]
-        }).dig($::fqdn, 'listen-addresses')
-                .then |$a| { $a + [ '127.0.0.1:80', '[::1]:80' ] }
-                .lest || { ['*:80'] }
+  $_enclosed_addresses = empty($listen_addr) ? {
+    true    => ['*'],
+    default => enclose_ipv6($listen_addr),
+  }
+  $vhost_listen = $_enclosed_addresses.map |$a| { "${a}:80" } .join(' ')
 
-        $vhost_listen = join([
-                *$listen_addresses,
-               has_role('bgp') ? {
-                       true => '193.31.7.2:80 [2a02:158:ffff:deb::2]:80',
-                       default => '',
-               }], ' ')
-       $onion_v4_addr = $::hostname ? {
-               mirror-bytemark => '5.153.231.45',
-               klecker    => '130.89.148.12',
-               mirror-isc => '149.20.4.15',
-               default    => undef,
-       }
+  $mirror_basedir_prefix = hiera('role_config__mirrors.mirror_basedir_prefix')
+  $archive_root = "${mirror_basedir_prefix}debian"
 
-       apache2::site { '010-ftp.debian.org':
-               site   => 'ftp.debian.org',
-               content => template('roles/apache-ftp.debian.org.erb'),
-       }
+  apache2::site { '010-ftp.debian.org':
+    site    => 'ftp.debian.org',
+    content => template('roles/apache-ftp.debian.org.erb'),
+  }
 
-       if has_role('debian_mirror_onion') {
-               if ! $onion_v4_addr {
-                       fail("Do not have an onion_v4_addr set for $::hostname.")
-               }
+  if $onion_service {
+    $onion_addr = empty($listen_addr) ? {
+      true    => $base::public_address,
+      default => filter_ipv4($listen_addr)[0]
+    }
+    if ! $onion_addr {
+      fail("Do not have a useable address for the onionservice on ${::hostname}.  Is \$listen_addr empty or does it not have an IPv4 address?.")
+    }
 
-               onion::service { 'ftp.debian.org':
-                       port => 80,
-                       target_port => 80,
-                       target_address => $onion_v4_addr,
-               }
-       }
+    onion::service { 'ftp.debian.org':
+      port           => 80,
+      target_port    => 80,
+      target_address => $onion_addr,
+    }
+  }
 
-        # roles is a list of hashes, which needs to be unpacked into a regular hash
-        $mirrors = hiera('roles.debian_mirror', [])
-        # unpack $mirrors and construct a hash
-        $m2 = Hash($mirrors.map |$h| { $h.map |$k, $v| { [$k, $v] }[0]})
-        $fastly_mirrors = $m2.filter |$h| { $h[1]['fastly-backend'] }
-        $hosts_to_check = $fastly_mirrors.map |$h| { $h[1]['service-hostname'] }
+  Ferm::Rule::Simple <<| tag == 'ssh::server::from::syncproxy' |>>
 
-        roles::mirror_health { 'ftp':
-               check_hosts   => $hosts_to_check,
-               check_service => 'ftp',
-               url           => 'http://debian.backend.mirrors.debian.org/debian/dists/sid/Release',
-               health_url    => 'http://debian.backend.mirrors.debian.org/_health',
-        }
+  mirror_health::service { 'ftp':
+    this_host_service_name => $healthcheck_name,
+    url                    => 'http://debian.backend.mirrors.debian.org/debian/dists/sid/Release',
+    health_url             => 'http://debian.backend.mirrors.debian.org/_health',
+  }
 }