Ask Your Question

exported resources are are not collected on host that exports them

asked 2015-01-20 11:20:15 -0600

Krist van Besien gravatar image

updated 2015-01-26 00:36:41 -0600

I have the following problem:

On a set of nodes I declare the following:

$factfile = '/etc7facter/facts.d/replicaset.txt'

@@concat::fragment {"replicaset_${::fqdn}":
    target => $factfile,
    content => "${::fqdn},",
    tag => 'replicaset',
    order => 3

  concat { $factfile:
    ensure => present

  concat::fragment {"replicaset":
    target => $factfile,
    content => "replicaset=",
    order => 1 

  Concat::Fragment <<| tag == 'replicaset' |>>

I expect now to have a custom fact, that contains all the fqdns of the hosts that have this snippet.

However, odly the host that declares this itself is not include.

So if I for example have this in the manifest for three nodes, s1, s2 and s3 then on s1 the factfile ends up containing


and on s2 it contains


In other words, the node is not collecting resources it exports itself. Why is that?

edit retag flag offensive close merge delete


is this a typo that you export a resource with tag `replicaset` but import resources with the tag `replica`?

Stefan gravatar imageStefan ( 2015-01-25 17:41:22 -0600 )edit

That was a typo. This is not a verbatim copy of my code.

Krist van Besien gravatar imageKrist van Besien ( 2015-01-26 00:37:01 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2015-04-23 16:40:33 -0600

cbarbour gravatar image

updated 2015-04-23 16:41:18 -0600

I remembered your question and revisited it.

When you export a resource to PuppetDB, the clientcert of the node that exported the resource is stored in PuppetDB along with the resource. When you collect resources, only resources from other nodes (clientcerts) are collected from PuppetDB.

A machine can collect it's own resources, but the collection is done by realizing the resources locally rather than by collecting the resources from PuppetDB. Thus, the following code will not work the way you expect:

case $::action {
  'export': {
    @@file { "/tmp/${::clientcert}.txt":
      ensure => 'file',
  'collect': {
    File <<| |>>

We could invoke this code using the following command line:

FACTER_action='export' puppet agent --test
FACTER_action='collect' puppet agent --test

This node will never be able to collect it's own resources because the logic prevents the resources from being declared and collected in the same compile run, and the node is prevented from collecting it's own resources from PuppetDB.

This example would work as expected:

@@file { "/tmp/${::clientcert}.txt":
  ensure => 'file',

File <<| |>>

I strongly suspect you're writing code that tests a condition and exports a resource one time. And I suspect your code is written so that the resources are not realized during the same run. Such an approach is not really declarative or idempotent under Puppet's model.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2015-01-20 11:20:15 -0600

Seen: 1,295 times

Last updated: Apr 23 '15