Skip to content

Commit 60a13ff

Browse files
committed
don't crash when host ssh public keys are missing
1 parent d101695 commit 60a13ff

2 files changed

Lines changed: 22 additions & 9 deletions

File tree

manifests/profile/known_host_public_keys.pp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,16 @@
1313
# only trusts the hosts; it does not actually grant access through a
1414
# firewall or anything.
1515
class nebula::profile::known_host_public_keys {
16-
$facts['ssh'].each |$name, $key_obj| {
17-
$type = $key_obj["type"]
18-
$key = $key_obj["key"]
16+
if $facts['ssh'] != undef {
17+
$facts['ssh'].each |$name, $key_obj| {
18+
$type = $key_obj["type"]
19+
$key = $key_obj["key"]
1920

20-
@@concat_fragment { "known host ${::networking['fqdn']} ${name}":
21-
tag => 'known_host_public_keys',
22-
target => '/etc/ssh/ssh_known_hosts',
23-
content => "${::networking['fqdn']} ${type} ${key}\n",
21+
@@concat_fragment { "known host ${::networking['fqdn']} ${name}":
22+
tag => 'known_host_public_keys',
23+
target => '/etc/ssh/ssh_known_hosts',
24+
content => "${::networking['fqdn']} ${type} ${key}\n",
25+
}
2426
}
2527
}
2628
}

spec/classes/profile/known_host_public_keys_spec.rb

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@
3030
}
3131
end
3232

33-
it { is_expected.to compile }
34-
3533
it "exports an ssh_known_hosts line for its ecdsa key" do
3634
expect(exported_resources).to contain_concat_fragment("known host example.invalid ecdsa")
3735
.with_target("/etc/ssh/ssh_known_hosts")
@@ -46,6 +44,19 @@
4644
.with_content("example.invalid ssh-rsa rsa_key\n")
4745
end
4846
end
47+
48+
context "with fqdn of example.invalid and some no ssh public keys" do
49+
let(:facts) do
50+
{
51+
networking: {
52+
ip: "0.1.2.3",
53+
fqdn: "example.invalid"
54+
},
55+
}
56+
end
57+
58+
it { is_expected.to compile }
59+
end
4960
end
5061
end
5162
end

0 commit comments

Comments
 (0)