Re: [Puppet Users] Prevent duplicate resources

2019-09-30 Thread jcbollinger


On Saturday, September 28, 2019 at 5:27:24 AM UTC-5, Martin Alfke wrote:
>
> Hi Timo, 
>
> there are two ways to achieve duplicate resource prevention: 
>
> 1. virtual resources 
>
> [...]
>
>  

> 2nd option is to use the ensure_packages or ensure_resources function (I 
> don't like this way as it hides what you want to achieve): 
>
>
 
I also dislike ensure_packages and ensure_resources, to the extent that I 
consider their usage an anti-pattern.  I have written here on that topic 
several times.  Use of virtual resources is better, but IMO *best* is (3) 
create a single class whose responsibility is or includes to manage the 
package in question, and to have other classes that require the package 
ensure it present by declaring the class responsible for that (with an 
include-like declaration, not a resource-like one).  This is one of the 
core use cases for the idempotency of classes.


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/bcea59bb-fd5b-4612-b3ae-66eb7b346996%40googlegroups.com.


Re: [Puppet Users] Prevent duplicate resources

2019-09-28 Thread Martin Alfke
Hi Timo,

there are two ways to achieve duplicate resource prevention:

1. virtual resources

migrate all packages which could be used by multiple classes into a separate 
class and mark them with the @-sign to be "virtual".
Virtual resources are not added to catalog onless you tell Puppet to realize or 
collect the resource.
Best practice is to provide information on when to manage the package via the 
"tag" metaparameter:

e.g.
site/profile/manifests/packages.pp
class profile::packages {
  @package { 'foo':
ensure => present,
tag   => ['web', 'db', 'storage'],
  }
  @package { 'bar':
ensure => present,
tag   => ['db', 'storage'],
  }
}

on the db, web, storage server profile add the collector for the required 
resource type:

class profile::db {
  Package <| tag == 'db' |>
}

site/profile/manifests/web.pp
class profile::web {
  Package <| tag == 'web' |>
}

site/profile/manifests/storage.pp
class profile::web {
  Package <| tag == 'storage' |>
}


2nd option is to use the ensure_packages or ensure_resources function (I don't 
like this way as it hides what you want to achieve):

site/profile/manifests/db.pp
site/profile/manifests/db.pp
class profile::db {
  ensure_packages(['foo', 'bar'], {ensure => present})
}

site/profile/manifests/web.pp
class profile::web {
  ensure_packages('foo', {ensure => present})
}

site/profile/manifests/storage.pp
class profile::web {
  ensure_packages(['foo', 'bar'], {ensure => present})
}

hth,
Martin


> On 27. Sep 2019, at 12:38, Timo Vlot  wrote:
> 
> Hi All,
> 
> We recently start with Puppet and during our introductory consultancy it was 
> mentioned that there is a "sneaky" way to define a resource (for example a 
> pakcage) in multiple classes that wouldn't cause the "duplicate resource" 
> errors. We have a few classes that rely on the same package being installed, 
> but cannot guarantee they are all attached to a node, as such we would need 
> to define the same package resource in all classes.
> 
> Does anyone know how to add a resource in multiple classes without the error?
> 
> thanx!
> 
> Timo
> 
> -- 
> 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/b690bc99-46cc-4130-b7ea-8f03442aa16d%40googlegroups.com.

-- 
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/C38915D8-513D-4B79-A986-56BB27EE2AAD%40gmail.com.


[Puppet Users] Prevent duplicate resources

2019-09-27 Thread Timo Vlot
Hi All,

We recently start with Puppet and during our introductory consultancy it 
was mentioned that there is a "sneaky" way to define a resource (for 
example a pakcage) in multiple classes that wouldn't cause the "duplicate 
resource" errors. We have a few classes that rely on the same package being 
installed, but cannot guarantee they are all attached to a node, as such we 
would need to define the same package resource in all classes.

Does anyone know how to add a resource in multiple classes without the 
error?

thanx!

Timo

-- 
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/b690bc99-46cc-4130-b7ea-8f03442aa16d%40googlegroups.com.