Overriding attributes of collected exported resources

This post is about a particularly elegant (and crucial) feature in puppet exported resources: attribute overriding. If you’re not already familiar with exported resources, you should start there, as they are the killer feature that makes configuration management with puppet awesome. (I haven’t found any explicit docs about this feature either, so feel free to comment if you know where they’re hidden.)

Setup: I’ve got a virtual machine which exports a resource to N different nodes. I’d like to define the resource with just one exported (@@) definition on my virtual machine.

Problem: One (or more) of the attributes needs to be changed based on which node it gets collected on. To make things more complicated, I’m using the same class definition on each of those N nodes to collect the resource. I don’t want to have to write N separate node definitions:

@@some::resource { 'the_name':
    foo => 'bar',
    #abc => 'different_on_each_node',
    tag => 'magic',

Solution: It turns out that for exported (or virtual) resources, you can specify attributes that get set upon collection. Naturally they can depend on a variable such as $name, which is unique to where they get collected:

Some::Resource <<| tag == 'magic' |>> {
    abc => "node-${name}",    # override!

Bonus: You can obviously use other variables throughout including in the collection (tag == ‘magic’) area, on both the source and the destination. Instead of a simple equality like I’ve used, you can actually specify a more complex expression, including other variables such as title (the $name).

Hope this takes your puppet coding to another level,

Happy hacking,



3 thoughts on “Overriding attributes of collected exported resources

  1. Thx a lot man!! I’ve been looking for a way how to modify exported resource, and the official puppet documentation somehow misses this feature of exported resources.

  2. First of all, Thanks a lot for your excellent blog ,

    I am trying to solve one problem using the exported resoueces and at the moment i am trying my head around to solve that ,
    Besically I have 500 server in my environment , This can be differentiated using hostname
    So my hostname is something like this SWSRVABC-[01…30], I have 9 different sites and 5 different types of servers in combination it make to 45, each will have unique configuration file for a module called ganglia

    In my ganglia module

    Each host from samesite and same description will have another 30 host inside the below parameter

    host= swsrvabc-01
    port = 8696
    ttl = 1
    host= swsrvabc-02
    port = 8696
    ttl = 1
    and so on to 30 … , this is same file in all the 30 hosts but different when it hits to different site and type of server.

    Whats the best way i can use the exported resources to push this configuration of different hosts but in the same site and description pool ?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s