Search code examples
modulepuppetfacter

Deploying a custom fact only to clients running a given module


I am trying to write a custom fact for linux servers that will give me all the folders under certain folder. The catch is that I need it to be deployed only on the the clients running the module that contains the fact -- it must not be deployed to other clients connecting to the same master.

Is there a way to do this?


Solution

  • Is there a way to do this?

    No, not with bona fide custom facts. Plugins, including custom facts, are synced prior to catalog building -- indeed, prior to any actual catalog request. This is necessary, at least for custom facts, because otherwise the values of those facts could not be used in catalog building.

    Because plugins are synced outside the scope of catalog building, pluginsync cannot know whether a given node's catalog will contain any classes or resources from any particular module, and therefore cannot use such information to filter plugins. Current Puppet does go to considerable effort to correctly identify a node's environment in order to sync the correct plugin versions, but at best that tells you only whether a node might use a given module, not whether it will do.

    You can accomplish roughly what you describe with an external fact managed via a File resource, but in this case you take direct responsibility for determining whether to manage that file, and every time a client issues a catalog request, it will use the fact definition provided by the previous Puppet run. That may be ok if you can get past the bootstrapping issue and if you carefully manage rollout of fact implementation changes.

    It may be that your overall goal would be served by confining your fact implementation. That does not prevent it from being deployed, but it can prevent the fact from being evaluated or reported.