ports_mirror: replace the vhost_listen string with an Array of IP addresses
[mirror/dsa-puppet.git] / modules / roles / manifests / ports_mirror.pp
1 # a mirror of ports.debian.org
2 #
3 # @param listen_addr IP addresses to have apache listen on
4 # @param onion_service provide the onion service from this host
5 class roles::ports_mirror(
6   Array[Stdlib::IP::Address] $listen_addr = [],
7   Boolean $onion_service = false,
8 ) {
9   include roles::archvsync_base
10
11   include apache2
12
13   $_enclosed_addresses = empty($listen_addr) ? {
14     true    => ['*'],
15     default => enclose_ipv6($listen_addr),
16   }
17   $_addr_port_elements = $_enclosed_addresses.map |$a| { "${a}:80" }
18   $vhost_listen = join($_addr_port_elements, ' ')
19
20   $mirror_basedir_prefix = hiera('role_config__mirrors.mirror_basedir_prefix')
21   $archive_root = "${mirror_basedir_prefix}debian-ports"
22
23   apache2::site { '010-ftp.ports.debian.org':
24     site    => 'ftp.ports.debian.org',
25     content => template('roles/apache-ftp.ports.debian.org.erb'),
26   }
27
28   if $onion_service {
29     $onion_addr = filter_ipv4($listen_addr)[0]
30     if ! $onion_addr {
31       fail("Do not have a useable address for the onionservice on ${::hostname}.  Is \$listen_addr empty or does it not have an IPv4 address?.")
32     }
33
34     onion::service { 'ftp.ports.debian.org':
35       port           => 80,
36       target_port    => 80,
37       target_address => $onion_addr,
38     }
39   }
40 }