Exported resources: how to avoid duplicate definitions?

1,088 views
Skip to first unread message

Martijn Grendelman

unread,
Nov 17, 2011, 5:51:14 AM11/17/11
to puppet...@googlegroups.com
Hi,

Is there a way to 'unique-ify' a collection of resources?

Suppose that nodes export '@@nagios_hostgroup' resources for hostgroups
that they want to be a member of. The Nagios server node collect those:

Nagios_hostgroup <<||>>

But many nodes export the same hostgroups, because the whole point of
having hostgroups is, that multiple hosts can be a member :-) So, the
collection would lead to duplicate definitions. Is there a way to avoid that?

Best regards,
Martijn Grendelman

Martijn Grendelman

unread,
Nov 17, 2011, 11:39:56 AM11/17/11
to puppet...@googlegroups.com

By Googling a bit, and reading some old stuff from the list, I got the
impression that it might be possible to just collect all those resources
without problems. So I set up a simple test case:

class testexport {


@@file {"/tmp/blub":
content => "fiep\n",
}
}

class testcollect {
File <<| tag == "testexport" |>>
}

node serverA {
include testexport
}

node serverB {
include testexport
}

node serverC {
include testcollect
}

As expected, on serverC, this leads to the following error:

err: Could not retrieve catalog from remote server: Error 400 on SERVER:
Exported resource File[/tmp/blub] cannot override local resource on node
serverC

Is there a way around this?

Best regards,
Martijn Grendelman

Sunny

unread,
Jan 6, 2012, 4:13:29 AM1/6/12
to Puppet Users
I too am facing the same issue.
I am deploying my infrastructure in AWS cloud.

err: Could not retrieve catalog from remote server: Error 400 on
SERVER: Exported resource Nagios_hostgroup[cluster_pm] cannot override
local resource on node ip-10-172-65-64.us-west-1.compute.internal

Does anybody know how to avoid this duplicate definitions. hosts and
hostgroups need to defined separately.

Thanks

windowsrefund

unread,
Jan 6, 2012, 11:55:11 AM1/6/12
to Puppet Users
The trick here is to realize that only the nagios server (the resource
collector) needs access to these resources. This means your clients
really do not need to export the resource at all. Instead, the
resources should be included in the manifest that ends up being
compiled by your nagios server(s). You're probably saying "Yes, but
how do I then control what hostgroup each client is a member of?". I
solve this problem with a combination of a node scoped variable and
the hostgroups parameter of the Nagios_host exported resource like so:

@@nagios_host {
hostgroups => inline_template("<%= has_variable?
('my_nagios_hostgroups') ? my_nagios_hostgroups : 'Other' %>"),
...

and of course, my nagios server's manifest then includes the hostgroup
resources

nagios_hostgroup { ['Awesome', 'Not Awesome', 'Other']:
ensure => present,
...
}

Best,
Adam

Adrián López Tejedor

unread,
Dec 27, 2013, 4:35:29 AM12/27/13
to puppet...@googlegroups.com
Here http://ttboj.wordpress.com/2013/06/04/collecting-duplicate-resources-in-puppet/ is explained how to do the "trick" to be allowed to define several times the same exported resource.

The basic idea is:
 - Create a custom defined type to be exported
 - That defined type should be exported always with different names ($fqdn for instance)
 - Inside that defined type, use ensure_resource() to create the needed resource (this method will create only one resource, no matter how many times is defined)

I have implemented my own solution:
Reply all
Reply to author
Forward
0 new messages