0

Is it possible to use the same exported resource in two different classes?

https://puppet.com/docs/puppet/5.2/lang_exported.html#exported-resource-collectors

For example, this will exports its own SSH host key and then collect the SSH host key of every node (including its own).

class hudson_destination::public_key {
  @@sshkey { "${fqdn}":
    type => rsa,
    key  => $sshrsakey,
    tag  => 'build_destination',
  }
}

I then collect this resource in another module that outputs to /etc/ssh/ssh_known_hosts files.

Sshkey <<| tag == 'build_destination' |>>

Can I use this collector in another class to output to, say ~/.ssh/known_hosts w/ a File resource?

*Note - I tried to duplicate the sshkey resource with a different title tag using:

@@sshkey { "${fqdn}_luntbld":
name => $fqdn,
type => rsa,
key  => $sshrsakey,
tag  => 'build_destination_luntbld',
target => '/com/home/luntbld/.ssh/known_hosts.puppet',

}

But go the error below about duplicate hostkeys already declared

Cannot alias Sshkey[fqdn_luntbld] to [\"yobot1.qa.norvax.net\"] at /etc/puppet/devqa/modules/hudson_destination/manifests/public_key.pp:22; resource [\"Sshkey\", \"yobot1.qa.norvax.net\"] already declared at /etc/puppet/devqa/modules/hudson_destination/manifests/public_key.pp:14 at /etc/puppet/devqa/modules/hudson_destination/manifests/public_key.pp:22 on node yobot1.qa.norvax.net\u001b[0m\n\u001b[1;31mWarning: Not using cache on failed catalog\u001b[0m\n\u001b[1;31mError: Could not retrieve catalog;

2
  • write a tiny class collecting what you want and use the class where need, try to organize your code without duplicate it.
    – c4f4t0r
    Dec 12, 2017 at 19:40
  • thanks, I will try that but rom what I understand, you can only declare a virtual resource once but collect it multiple times. I will add an additional collect and try that route. Found this that says i can override attributes when collecting, will post if i am successful. ttboj.wordpress.com/2013/05/14/…
    – romedawg
    Dec 14, 2017 at 21:25

0

You must log in to answer this question.

Browse other questions tagged .