Add lindsay and pinel volumes at ubc
[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         $direct = false
7 ) {
8         if ($ensure == "ifstatic") {
9                 $my_ensure = has_static_component($name) ? {
10                         true => "present",
11                         false => "absent"
12                 }
13         } else {
14                 $my_ensure = $ensure
15         }
16
17         if ($my_ensure == "present") {
18                 include onion
19
20                 concat::fragment { "onion::torrc_onionservice::${name}":
21                         target  => "/etc/tor/torrc",
22                         order   => '50',
23                         content  => @("EOF"),
24                                 HiddenServiceDir /var/lib/tor/onion/${name}
25                                 HiddenServiceVersion 2
26                                 HiddenServicePort ${port} ${target_address}:${target_port}
27
28                                 | EOF
29                 }
30
31                 $onion_hn = onion_tor_service_hostname($name)
32                 if $onion_hn {
33                         $hostname_without_onion = regsubst($onion_hn, '\.onion$', '')
34
35                         if ($direct) {
36                                 @@concat::fragment { "onion::balance::onionbalance-services.yaml::${name}":
37                                         target  => "/srv/puppet.debian.org/puppet-facts/onionbalance-services.yaml",
38                                         content => "{\"${name}\": \"${onion_hn}\"}\n",
39                                         tag     => "onionbalance-services.yaml",
40                                 }
41                         } else {
42                                 @@concat::fragment { "onion::balance::instance::dsa-snippet::$name::$fqdn":
43                                         target  => "/etc/onionbalance/config-dsa-snippet.yaml",
44                                         content => "- service: ${name}\n  address: ${hostname_without_onion}\n  name: ${hostname}-${name}\n",
45                                         tag     => "onion::balance::dsa-snippet",
46                                 }
47                         }
48                 }
49         } elsif ($my_ensure == "absent") {
50                 file { "/var/lib/tor/onion/${name}":
51                         ensure => absent,
52                         force  => true,
53                 }
54         } else {
55                 fail("Invalid ensure value ${my_ensure}")
56         }
57 }