Skip to content

Commit 818e45b

Browse files
committed
(MODULES-10827) Exported sshkey already exists error
Using module https://github.com/ghoneycutt/puppet-module-ssh to export and collect sshkey resources from nodes, an 'already declared' error appears. This happened because when the catalog is first converted to resouces, the sshkey resource is added via https://github.com/puppetlabs/puppet/blob/main/lib/puppet/resource/catalog.rb#L137, where 'resource.ref'(https://github.com/puppetlabs/puppet/blob/main/lib/puppet/type.rb#L2548) uses 'self.title'. Since self.title goes to the title method defined in type.rb, it will return a different title than the title method from https://github.com/puppetlabs/puppetlabs-sshkeys_core/blob/main/lib/puppet/provider/sshkey/parsed.rb#L31. This mismatch try to add both resource, resulting in the 'already declared' error.
1 parent 8683821 commit 818e45b

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

lib/puppet/type/sshkey.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ def name
1212
"#{self[:name]}@#{self[:type]}"
1313
end
1414

15+
alias_method :title, :name
16+
1517
def self.parameters_to_include
1618
[:name, :type]
1719
end

spec/unit/type/sshkey_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,5 +81,10 @@
8181
described_class.new(name: 'host,host.domain,ip')
8282
}.to raise_error(Puppet::Error, %r{No comma in resourcename})
8383
end
84+
85+
it 'aliases :title to :name' do
86+
key = described_class.new(name: 'foo', type: :rsa)
87+
expect(key.name).to eq key.title
88+
end
8489
end
8590
end

0 commit comments

Comments
 (0)