Skip to content

Commit e922db3

Browse files
committed
Refactor ssh template
1 parent 6387571 commit e922db3

File tree

2 files changed

+49
-28
lines changed

2 files changed

+49
-28
lines changed

manifests/service/ssh.pp

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,55 @@
3939
},
4040
)
4141
} else {
42+
# Build configuration content for the SSH service
43+
$_base_content = [
44+
'# sssd::service::ssh',
45+
'[ssh]',
46+
]
47+
48+
# Add conditional parameters if defined
49+
if $description {
50+
$_description_entries = ["description = ${description}"]
51+
} else {
52+
$_description_entries = []
53+
}
54+
55+
if $debug_level {
56+
$_debug_level_entries = ["debug_level = ${debug_level}"]
57+
} else {
58+
$_debug_level_entries = []
59+
}
60+
61+
$_debug_timestamps_entries = $debug_timestamps ? {
62+
true => ['debug_timestamps = true'],
63+
false => ['debug_timestamps = false'],
64+
}
65+
66+
$_debug_microseconds_entries = $debug_microseconds ? {
67+
true => ['debug_microseconds = true'],
68+
false => ['debug_microseconds = false'],
69+
}
70+
71+
$_ssh_hash_known_hosts_entries = $ssh_hash_known_hosts ? {
72+
true => ['ssh_hash_known_hosts = true'],
73+
false => ['ssh_hash_known_hosts = false'],
74+
}
75+
76+
if $ssh_known_hosts_timeout {
77+
$_ssh_known_hosts_timeout_entries = ["ssh_known_hosts_timeout = ${ssh_known_hosts_timeout}"]
78+
} else {
79+
$_ssh_known_hosts_timeout_entries = []
80+
}
81+
82+
# Combine all configuration entries in the expected order
83+
$_all_entries = $_base_content + $_description_entries + $_debug_level_entries + $_debug_timestamps_entries + $_debug_microseconds_entries + $_ssh_hash_known_hosts_entries + $_ssh_known_hosts_timeout_entries
84+
85+
$_final_content = $_all_entries.join("\n")
86+
4287
$_content = epp(
4388
"${module_name}/service/ssh.epp",
4489
{
45-
'description' => $description,
46-
'debug_level' => $debug_level,
47-
'debug_timestamps' => $debug_timestamps,
48-
'debug_microseconds' => $debug_microseconds,
49-
'ssh_hash_known_hosts' => $ssh_hash_known_hosts,
50-
'ssh_known_hosts_timeout' => $ssh_known_hosts_timeout,
90+
'content' => $_final_content,
5191
},
5292
)
5393
}

templates/service/ssh.epp

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,4 @@
1-
<% |
2-
Optional[String] $description,
3-
Optional[Sssd::DebugLevel] $debug_level,
4-
Boolean $debug_timestamps,
5-
Boolean $debug_microseconds,
6-
Boolean $ssh_hash_known_hosts,
7-
Optional[Integer] $ssh_known_hosts_timeout,
1+
<%- |
2+
String $content,
83
| -%>
9-
10-
# sssd::service::ssh
11-
[ssh]
12-
<% if $description { -%>
13-
description = <%= $description %>
14-
<% } -%>
15-
<% if $debug_level { -%>
16-
debug_level = <%= $debug_level %>
17-
<% } -%>
18-
debug_timestamps = <%= $debug_timestamps %>
19-
debug_microseconds = <%= $debug_microseconds %>
20-
ssh_hash_known_hosts = <%= $ssh_hash_known_hosts %>
21-
<% if $ssh_known_hosts_timeout { -%>
22-
ssh_known_hosts_timeout = <%= $ssh_known_hosts_timeout %>
23-
<% } -%>
4+
<%= $content %>

0 commit comments

Comments
 (0)