Skip to content

Commit 8849dd2

Browse files
committed
Manage value of SYSTEMD_RESOLVED_SYNTHESIZE_HOSTNAME
systemd version v258 >= (e.g EL10) now synthesizes the resolution of the local hostname by default. Under certain circumstances it is useful to disable this feature. Setting the parameter `resolved_synthesize_hostname` to false will disable localhost hostname synthesis. https://github.com/systemd/systemd/blob/f784a63cfad6a5425af2ebc02a1f9effec4fd079/docs/ENVIRONMENT.md?plain=1#L388C5-L388C41
1 parent 8f8ea91 commit 8849dd2

File tree

4 files changed

+71
-0
lines changed

4 files changed

+71
-0
lines changed

REFERENCE.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ The following parameters are available in the `systemd` class:
205205
* [`resolved_ensure`](#-systemd--resolved_ensure)
206206
* [`resolved_package`](#-systemd--resolved_package)
207207
* [`resolved_libraries`](#-systemd--resolved_libraries)
208+
* [`resolved_synthesize_hostname`](#-systemd--resolved_synthesize_hostname)
208209
* [`manage_nspawn`](#-systemd--manage_nspawn)
209210
* [`nspawn_package`](#-systemd--nspawn_package)
210211
* [`dns`](#-systemd--dns)
@@ -351,6 +352,14 @@ List of library packages needed for systemd-resolved.
351352

352353
Default value: `[]`
353354

355+
##### <a name="-systemd--resolved_synthesize_hostname"></a>`resolved_synthesize_hostname`
356+
357+
Data type: `Optional[Boolean]`
358+
359+
Control if the hostname lookup via systemd should be synthesized.
360+
361+
Default value: `undef`
362+
354363
##### <a name="-systemd--manage_nspawn"></a>`manage_nspawn`
355364

356365
Data type: `Boolean`

manifests/init.pp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
# @param resolved_libraries
3535
# List of library packages needed for systemd-resolved.
3636
#
37+
# @param resolved_synthesize_hostname
38+
# Control if the hostname lookup via systemd should be synthesized.
39+
#
3740
# @param manage_nspawn
3841
# Manage the systemd-nspawn@service and machinectl subsystem.
3942
#
@@ -265,6 +268,7 @@
265268
Optional[Enum['systemd-resolved']] $resolved_package = undef,
266269
Array[String[1]] $resolved_libraries = [],
267270
Enum['stopped','running'] $resolved_ensure = 'running',
271+
Optional[Boolean] $resolved_synthesize_hostname = undef,
268272
Optional[Variant[Array[String],String]] $dns = undef,
269273
Optional[Variant[Array[String],String]] $fallback_dns = undef,
270274
Optional[Variant[Array[String],String]] $domains = undef,

manifests/resolved.pp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@
4848
# Takes a boolean argument. When "false" (default) it uses /run/systemd/resolve/resolv.conf
4949
# as /etc/resolv.conf. When "true", it uses /run/systemd/resolve/stub-resolv.conf
5050
#
51+
# @param resolved_synthesize_hostname
52+
# Should systemd-resolved synthesize the lookup of the hostname
53+
#
5154
class systemd::resolved (
5255
Enum['stopped','running'] $ensure = $systemd::resolved_ensure,
5356
Optional[Variant[Array[String],String]] $dns = $systemd::dns,
@@ -61,6 +64,7 @@
6164
Optional[Variant[Boolean,Enum['udp', 'tcp','absent']]] $dns_stub_listener = $systemd::dns_stub_listener,
6265
Optional[Variant[Array[String[1]],Enum['absent']]] $dns_stub_listener_extra = $systemd::dns_stub_listener_extra,
6366
Boolean $use_stub_resolver = $systemd::use_stub_resolver,
67+
Optional[Boolean] $resolved_synthesize_hostname = $systemd::resolved_synthesize_hostname,
6468
) {
6569
assert_private()
6670

@@ -99,6 +103,21 @@
99103
}
100104
}
101105

106+
$_syn_ensure = $resolved_synthesize_hostname ? {
107+
Boolean => 'present',
108+
default => 'absent',
109+
}
110+
$_syn_service = $resolved_synthesize_hostname ? {
111+
Boolean => { 'Environment' => "SYSTEMD_RESOLVED_SYNTHESIZE_HOSTNAME=${bool2str($resolved_synthesize_hostname,'1','0')}" },
112+
default => undef,
113+
}
114+
systemd::manage_dropin { 'synthesize_hostname.conf':
115+
ensure => $_syn_ensure,
116+
unit => 'systemd-resolved.service',
117+
service_entry => $_syn_service,
118+
notify_service => true,
119+
}
120+
102121
if $dns {
103122
if $dns =~ String {
104123
$_dns = $dns

spec/classes/init_spec.rb

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,13 @@
4040
it { is_expected.to create_service('systemd-networkd').with_ensure('running') }
4141
it { is_expected.to create_service('systemd-networkd').with_enable(true) }
4242
it { is_expected.not_to contain_file('/etc/systemd/network') }
43+
it { is_expected.to contain_systemd__manage_dropin('synthesize_hostname.conf').with_ensure('absent') }
4344

4445
if facts[:os]['family'] == 'RedHat'
4546
it { is_expected.to contain_package('systemd-networkd') }
4647
else
4748
it { is_expected.not_to contain_package('systemd-networkd') }
49+
4850
end
4951

5052
if (facts[:os]['family'] == 'RedHat' && facts[:os]['release']['major'] != '8') || (facts[:os]['name'] == 'Debian' && facts[:os]['release']['major'].to_i >= 12) || (facts[:os]['name'] == 'Ubuntu' && facts[:os]['release']['major'].to_i >= 24)
@@ -259,6 +261,43 @@
259261
}
260262
end
261263

264+
context 'when resolved_synthesize_hostname true' do
265+
let(:params) do
266+
{
267+
manage_resolved: true,
268+
resolved_synthesize_hostname: true,
269+
}
270+
end
271+
272+
it {
273+
is_expected.to contain_systemd__manage_dropin('synthesize_hostname.conf').with(
274+
{
275+
ensure: 'present',
276+
service_entry: { 'Environment' => 'SYSTEMD_RESOLVED_SYNTHESIZE_HOSTNAME=1' },
277+
}
278+
)
279+
}
280+
end
281+
282+
context 'when resolved_synthesize_hostname false' do
283+
let(:params) do
284+
{
285+
manage_resolved: true,
286+
resolved_synthesize_hostname: false,
287+
}
288+
end
289+
290+
it {
291+
is_expected.to contain_systemd__manage_dropin('synthesize_hostname.conf').with(
292+
{
293+
ensure: 'present',
294+
unit: 'systemd-resolved.service',
295+
service_entry: { 'Environment' => 'SYSTEMD_RESOLVED_SYNTHESIZE_HOSTNAME=0' },
296+
}
297+
)
298+
}
299+
end
300+
262301
context 'with alternate target' do
263302
let(:params) do
264303
{

0 commit comments

Comments
 (0)