Skip to content

Commit

Permalink
Add for the possibility of an IPv6 address
Browse files Browse the repository at this point in the history
Also cover the case that there is no IPv4 address on an IPv6 only host.

Included are rspec tests for the sshkey resource

Test for correct host_aliases for the host's own sshkey resource.
3 possible combinations of IPv4 and IPv6 address are tested.
Not tested are:
- Virtual sshkey resources from other hosts.
- Other parameters for the sshkey resource (type, key)
- Non-default values for ssh_key_ensure and ssh_key_import.
  • Loading branch information
bjvrielink committed Apr 29, 2019
1 parent 60562d7 commit 9832dee
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
10 changes: 9 additions & 1 deletion manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -974,10 +974,18 @@
}
}

# If either IPv4 or IPv6 stack is not configured on the agent, the
# corresponding $::ipaddress(6)? fact is not present. So, we cannot assume
# these variables are defined. Getvar (Stdlib 4.13+, ruby 1.8.7+) handles
# this correctly.
if getvar('::ipaddress') and getvar('::ipaddress6') { $host_aliases = [$::hostname, $::ipaddress, $::ipaddress6] }
elsif getvar('::ipaddress6') { $host_aliases = [$::hostname, $::ipaddress6] }
else { $host_aliases = [$::hostname, $::ipaddress] }

# export each node's ssh key
@@sshkey { $::fqdn :
ensure => $ssh_key_ensure,
host_aliases => [$::hostname, $::ipaddress],
host_aliases => $host_aliases,
type => $ssh_key_type,
key => $key,
}
Expand Down
26 changes: 26 additions & 0 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,32 @@
}

it { should have_ssh__config_entry_resource_count(0) }

context 'with exported sshkey resources' do
subject { exported_resources}
context 'With only IPv4 address' do
let(:facts) { default_facts.merge( facts )}
it { should contain_sshkey('monkey.example.com').with(
'ensure' => 'present',
'host_aliases' => ['monkey', '127.0.0.1']
)}
end
context 'With dual stack IP' do
let(:facts) { default_facts.merge({ :ipaddress6 => 'dead:beef::1/64' }) }
it { should contain_sshkey('monkey.example.com').with(
'ensure' => 'present',
'host_aliases' => ['monkey', '127.0.0.1', 'dead:beef::1/64']
)}
end
context 'With only IPv6 address' do
let(:facts) { default_facts.merge({ :ipaddress6 => 'dead:beef::1/64', :ipaddress => nil }) }
it { should contain_sshkey('monkey.example.com').with(
'ensure' => 'present',
'host_aliases' => ['monkey', 'dead:beef::1/64']
)}
end
end

end
end

Expand Down

0 comments on commit 9832dee

Please sign in to comment.