Collecting exported resource multiple times

asked 2017-12-12 09:11:45 -0600

shoemonkey gravatar image

updated 2017-12-12 10:53:08 -0600

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

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 {

  # Publish this host's public key so that the build-slaves can put it in their respective /etc/ssh/ssh_known_hosts files.
  # ${fqdn} and ${sshrsakey} are Facter facts
  @@sshkey { "${fqdn}":
    type => rsa,
    key  => $sshrsakey,
    tag  => 'build_destination',

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

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

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

I tried to duplicate the virtual resource by adding this below to the same class and collecting the resource but got this error.

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

But received this error.

Cannot alias Sshkey[fqdn_luntbld] to [\"\"] at /etc/puppet/devqa/modules/hudson_destination/manifests/public_key.pp:22; resource [\"Sshkey\", \"\"] 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\u001b[0m\n\u001b[1;31mWarning: Not using cache on failed catalog\u001b[0m\n\u001b[1;31mError: Could not retrieve catalog;
edit retag flag offensive close merge delete


You can export resources with a given title only once, but collect them several times.

Kai Burghardt gravatar imageKai Burghardt ( 2017-12-12 13:56:01 -0600 )edit

When I try to collect a 2nd time, can I output to a different location? Sshkey <<| tag == 'build_destination' |>> #this will output to /etc/ssh/ssh_known_hosts Sshkey_home_dir <<| tag == 'build_destination' |>> # can I set this to ~/.ssh/known_hosts

shoemonkey gravatar imageshoemonkey ( 2017-12-12 14:13:31 -0600 )edit