On Monday, September 10, 2018 at 11:18:34 AM UTC-5, Michael Watters wrote:
>
> I'd prefer to see the entire vhost.pp code but it looks like the issue is 
> the same as I mentioned previously, you have multiple atqapache::vhost 
> resources attempting to manage the client base directory.  I've ran into a 
> similar issue with my own modules and was able to hack around it using the 
> defined() function.  For example:
>
> if !defined(File["$client_base"]) {
>    file { [ "$client_base", ]:
>       ensure  => 'directory',
>       owner   => "$owner",
>       group   => "$group",
>       mode    => 0744,
>     }
> }
>
> There may be a better option but this way ensures that the resource is 
> only created once.
>
>
Just about any viable alternative is better than using defined().  If you 
are in control of all the code that may declare that resource then among 
the best options are

   - factor out the declaration into a separate class, and declare the 
   class, where needed, via an include-like class declaration.  Unlike 
   resources, classes can safely be declared multiple times, as long as all 
   the declarations except possibly the first-evaluated one are of the 
   include-like kind.
   - A more old-school way would be to move the resource declaration to 
   another existing class that you can rely upon to be included, and make it 
   virtual.  Then *realize* it in the places where presently you declare it.
   - Or perhaps there is already a class that provides an appropriate 
   context and scope such that you can move the declaration to that class and 
   leave it concrete.

If you do not have full control of all the declarations and cannot obtain 
it, then

   - At minimum, using the ensure_resource() function from 
   puppetlabs/stdlib is slightly less evil than using defined() for this 
   purpose.


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/ec0b6f76-7891-4f8b-988e-d059d7d9a793%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to