Add onion services for a bunch of static things
[mirror/dsa-puppet.git] / modules / onion / manifests / service.pp
1 define onion::service (
2         $port,
3         $target_address,
4         $target_port,
5         $ensure = present
6 ) {
7         if ($ensure == "ifstatic") {
8                 $my_ensure = has_static_component($name) ? {
9                         true => "present",
10                         false => "absent"
11                 }
12         } else {
13                 $my_ensure = $ensure
14         }
15
16         if ($my_ensure == "present") {
17                 include onion
18
19                 concat::fragment { "onion::torrc_onionservice::${name}":
20                         target  => "/etc/tor/torrc",
21                         order   => 50,
22                         content => "HiddenServiceDir /var/lib/tor/onion/${name}\nHiddenServicePort ${port} ${target_address}:${target_port}\n\n",
23                 }
24
25                 $onion_hn = onion_tor_service_hostname($name)
26                 if $onion_hn {
27                         $hostname_without_onion = regsubst($onion_hn, '\.onion$', '')
28                         @@concat::fragment { "onion::balance::instance::$name::$fqdn":
29                                 target  => "/etc/onionbalance/config.yaml",
30                                 content => "      - address: ${hostname_without_onion}\n        name: ${hostname}-${name}\n",
31                                 order   => "50-${name}-20",
32                                 tag     => "onion::balance::$name",
33                         }
34                 }
35         }
36 }