On Wednesday, January 15, 2014 4:28:41 AM UTC-6, shlo....@gmail.com wrote:
>
>
>
> Hi,
> I want to write a function for Puppet that check if package already 
> defined, I saw in this group to do:
>
> define safepackage ( $ensure = present ) {
>         if !defined(Package[$title]) {
>                 package { $title: ensure => $ensure }
>         }
> }
>
> In which file I need put this function so all other modules can access 
> it?  because I'm getting 'unknown function...' error.
>
>
That's not a function, it's a defined type.  You declare instances just as 
you would declare instances of a built-in type, such as Package itself.  
You cannot call it as if it were a function.  You really ought to put it 
into a module, though.

With that said, what you propose to do is one of the persistent bad ideas 
in the Puppet universe.  Using such a definition to allow multiple points 
of declaration of a given resource (only one of which will be effective) 
makes your manifest set harder to maintain and opens it to subtle bugs 
because you must keep all declarations of the target resource 
synchronized.  If you don't, then your manifest set thereby has an internal 
inconsistency that you prevent Puppet from diagnosing.  All manner of 
strangeness may then ensue.  Moreover, the approach is only effective for a 
given resource if you apply it to every declaration of that resource.

The best way to avoid multiple-declaration errors is to factor out multiple 
declarations of any given resource into a single class that the other 
erstwhile declaration points will rely on.  That is usually fairly 
natural.  It may involve modifying third-party modules, but so does any 
approach based on the defined() function or similar.


John

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to puppet-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/cd5166e6-347f-495c-b14e-62ab417e0774%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to