Add systemd module, required by rabbitmq
[mirror/dsa-puppet.git] / 3rdparty / modules / systemd / manifests / resolved.pp
1 # **NOTE: THIS IS A [PRIVATE](https://github.com/puppetlabs/puppetlabs-stdlib#assert_private) CLASS**
2 #
3 # This class provides an abstract way to trigger resolved.
4 # Each parameters correspond to resolved.conf(5):
5 # https://www.freedesktop.org/software/systemd/man/resolved.conf.html
6 #
7 # @param ensure
8 #   The state that the ``resolved`` service should be in
9 #
10 # @param dns
11 #   A space-separated list of IPv4 and IPv6 addresses to use as system DNS servers.
12 #   DNS requests are sent to one of the listed DNS servers in parallel to suitable
13 #   per-link DNS servers acquired from systemd-networkd.service(8) or set at runtime
14 #   by external applications. requires puppetlabs-inifile
15 #
16 # @param fallback_dns
17 #   A space-separated list of IPv4 and IPv6 addresses to use as the fallback DNS
18 #   servers. Any per-link DNS servers obtained from systemd-networkd take
19 #   precedence over this setting. requires puppetlabs-inifile
20 #
21 # @param domains
22 #   A space-separated list of domains host names or IP addresses to be used
23 #   systemd-resolved take precedence over this setting.
24 #
25 # @param llmnr
26 #   Takes a boolean argument or "resolve".
27 #
28 # @param multicast_dns
29 #   Takes a boolean argument or "resolve".
30 #
31 # @param dnssec
32 #   Takes a boolean argument or "allow-downgrade".
33 #
34 # @param cache
35 #   Takes a boolean argument.
36 #
37 # @param dns_stub_listener
38 #   Takes a boolean argument or one of "udp" and "tcp".
39 #
40 # @param use_stub_resolver
41 #   Takes a boolean argument. When "false" (default) it uses /var/run/systemd/resolve/resolv.conf
42 #   as /etc/resolv.conf. When "true", it uses /var/run/systemd/resolve/stub-resolv.conf
43 #
44 class systemd::resolved (
45   Enum['stopped','running'] $ensure                                = $systemd::resolved_ensure,
46   Optional[Variant[Array[String],String]] $dns                     = $systemd::dns,
47   Optional[Variant[Array[String],String]] $fallback_dns            = $systemd::fallback_dns,
48   Optional[Variant[Array[String],String]] $domains                 = $systemd::domains,
49   Optional[Variant[Boolean,Enum['resolve']]] $llmnr                = $systemd::llmnr,
50   Optional[Variant[Boolean,Enum['resolve']]] $multicast_dns        = $systemd::multicast_dns,
51   Optional[Variant[Boolean,Enum['allow-downgrade']]] $dnssec       = $systemd::dnssec,
52   Boolean $cache                                                   = $systemd::cache,
53   Optional[Variant[Boolean,Enum['udp', 'tcp']]] $dns_stub_listener = $systemd::dns_stub_listener,
54   Boolean $use_stub_resolver                                       = $systemd::use_stub_resolver,
55 ){
56
57   assert_private()
58
59   $_enable_resolved = $ensure ? {
60     'stopped' => false,
61     'running' => true,
62     default   => $ensure,
63   }
64
65   service { 'systemd-resolved':
66     ensure => $ensure,
67     enable => $_enable_resolved,
68   }
69
70   $_resolv_conf_target = $use_stub_resolver ? {
71     true    => '/run/systemd/resolve/stub-resolv.conf',
72     default => '/run/systemd/resolve/resolv.conf',
73   }
74   file { '/etc/resolv.conf':
75     ensure  => 'symlink',
76     target  => $_resolv_conf_target,
77     require => Service['systemd-resolved'],
78   }
79
80   if $dns {
81     if $dns =~ String {
82       $_dns = $dns
83     } else {
84       $_dns = join($dns, ' ')
85     }
86     ini_setting{ 'dns':
87       ensure  => 'present',
88       value   => $_dns,
89       setting => 'DNS',
90       section => 'Resolve',
91       path    => '/etc/systemd/resolved.conf',
92       notify  => Service['systemd-resolved'],
93     }
94   }
95
96   if $fallback_dns {
97     if $fallback_dns =~ String {
98       $_fallback_dns = $fallback_dns
99     } else {
100       $_fallback_dns = join($fallback_dns, ' ')
101     }
102     ini_setting{ 'fallback_dns':
103       ensure  => 'present',
104       value   => $_fallback_dns,
105       setting => 'FallbackDNS',
106       section => 'Resolve',
107       path    => '/etc/systemd/resolved.conf',
108       notify  => Service['systemd-resolved'],
109     }
110   }
111
112   if $domains {
113     if $domains =~ String {
114       $_domains = $domains
115     } else {
116       $_domains = join($domains, ' ')
117     }
118     ini_setting{ 'domains':
119       ensure  => 'present',
120       value   => $_domains,
121       setting => 'Domains',
122       section => 'Resolve',
123       path    => '/etc/systemd/resolved.conf',
124       notify  => Service['systemd-resolved'],
125     }
126   }
127
128   $_llmnr = $llmnr ? {
129     true    => 'yes',
130     false   => 'no',
131     default => $llmnr,
132   }
133
134   if $_llmnr {
135     ini_setting{ 'llmnr':
136       ensure  => 'present',
137       value   => $_llmnr,
138       setting => 'LLMNR',
139       section => 'Resolve',
140       path    => '/etc/systemd/resolved.conf',
141       notify  => Service['systemd-resolved'],
142     }
143   }
144
145   $_multicast_dns = $multicast_dns ? {
146     true    => 'yes',
147     false   => 'no',
148     default => $multicast_dns,
149   }
150
151   if $_multicast_dns {
152     ini_setting{ 'multicast_dns':
153       ensure  => 'present',
154       value   => $_multicast_dns,
155       setting => 'MulticastDNS',
156       section => 'Resolve',
157       path    => '/etc/systemd/resolved.conf',
158       notify  => Service['systemd-resolved'],
159     }
160   }
161
162   $_dnssec = $dnssec ? {
163     true    => 'yes',
164     false   => 'no',
165     default => $dnssec,
166   }
167
168   if $_dnssec {
169     ini_setting{ 'dnssec':
170       ensure  => 'present',
171       value   => $_dnssec,
172       setting => 'DNSSEC',
173       section => 'Resolve',
174       path    => '/etc/systemd/resolved.conf',
175       notify  => Service['systemd-resolved'],
176     }
177   }
178
179   $_cache = $cache ? {
180     true    => 'yes',
181     false   => 'no',
182   }
183
184   if $cache {
185     ini_setting{ 'cache':
186       ensure  => 'present',
187       value   => $_cache,
188       setting => 'Cache',
189       section => 'Resolve',
190       path    => '/etc/systemd/resolved.conf',
191       notify  => Service['systemd-resolved'],
192     }
193   }
194
195   $_dns_stub_listener = $dns_stub_listener ? {
196     true    => 'yes',
197     false   => 'no',
198     default => $dns_stub_listener,
199   }
200
201   if $_dns_stub_listener {
202     ini_setting{ 'dns_stub_listener':
203       ensure  => 'present',
204       value   => $_dns_stub_listener,
205       setting => 'DNSStubListener',
206       section => 'Resolve',
207       path    => '/etc/systemd/resolved.conf',
208       notify  => Service['systemd-resolved'],
209     }
210   }
211
212 }