Add for the possibility of an IPv6 address
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.
This commit is contained in:
parent
60562d7071
commit
9832dee0a0
@ -974,10 +974,18 @@ class ssh (
|
||||
}
|
||||
}
|
||||
|
||||
# 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,
|
||||
}
|
||||
|
@ -311,6 +311,32 @@ describe 'ssh' do
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user