Issue #3181 has been updated by Tim Stoop.
Currently, I'm working on our new Nagios module, so my example is Nagios
orientated, but I'm sure you can see the benefit for other resources too.
Mainly I'd like to use it for "magic resource creation". Take the example
below, hostgroups aren't very interesting and we never use any other option
than giving them a name, so we can more easily search for them in the Nagios
interface. Actually, I don't even know if there are other options at all... I
use the syntax I proposed in the ticket, just for clarity's sake.
<pre>
define monitor_host ($hostgroups = "", ... ) {
?@@nagios_hostgroup { $hostgroups:
target => "/etc/nagios3/conf.d/hostgroups.cfg",
tag => "monitor-local",
}
?@@file { "/etc/nagios3/conf.d/hostgroups.cfg":
owner => "nagios",
}
@@nagios_host { $name:
hostgroups => $hostgroups,
...
}
}
</pre>
This can be done using 'if ! defined' when you only enter one hostgroup, but
it's impossible if you want to do this with multiple hostgroups.
The idea is that there's a lot of automation you can do with puppet that
requires the creation of 'stock' resources, which can be created if you only
know their name. Allowing for this request, would make it easier to handle
arrays for this.
Another way to solve it, is by creating loop controls for arrays in the puppet
DSL. That might actually solve even more problems than just the resource
creation for resources that might already be created. That way you could do
something like:
<pre>
if $hostgroups {
for group in $hostgroups {
if ! defined(Nagios_hostgroup[$group]) {
@@nagios_hostgroup { $group:; }
}
etc.
}
}
</pre>
PS. I believe nagios_host's hostgroups setting currently doesn't allow arrays,
but that's easily fixed with an inline_template or if #2990 gets accepted.
----------------------------------------
Feature #3181: Create resource if it doesn't already exist (with array support)
http://projects.reductivelabs.com/issues/3181
Author: Tim Stoop
Status: Needs more information
Priority: Normal
Assigned to:
Category: functions
Target version:
Affected version: 0.25.4
Keywords:
Branch:
Hi all,
I'm currently looking for a way to say something like "create this resource if
it doesn't already exist". The current way to do this, is simply checking with
<pre>if ! defined(Resource['$resname']) { resource{ '$resname':; } }</pre>
which works with strings, but doesn't support arrays. And I'm running into
several cases in which it would save me a lot of work if I could make this work
if $resname is an array. I think more people can do something useful with this
kind of functionality.
Although you probably have a better idea what would fit, a syntax that would
work for this is something like
<pre>?resource { '$resname':; }</pre>
Would be especially useful if it could also support virtual/exported resources,
like so, for example:
<pre>?@@resource { '$resname':; }</pre>
Thanks in advance for considering this!
--
You have received this notification because you have either subscribed to it,
or are involved in it.
To change your notification preferences, please click here:
http://reductivelabs.com/redmine/my/account
--
You received this message because you are subscribed to the Google Groups
"Puppet Bugs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/puppet-bugs?hl=en.