On Fri, Jul 12, 2013 at 8:11 AM, Christian Flamm <
[email protected]> wrote:

>
>
> Am Freitag, 12. Juli 2013 17:03:11 UTC+2 schrieb Nan Liu:
>
>> On Fri, Jul 12, 2013 at 7:45 AM, Christian Flamm 
>> <[email protected]>wrote:
>>
>>> Hi,
>>> I'm having trouble understanding the added value Virtual Resources
>>> provide. Let's say I'm having two different modules (that usually are
>>> assigned to different agents) that both contain a common resource (let's
>>> say a user). If I want to easily make it possible to assign both modules to
>>> the same agent - without suffering from the "duplicate resource
>>> declaration" error - I could make the resource definition virtual and
>>> realize it in different modules. See this simplified example.
>>>
>>> > cat $modulesdir/virtual/manifests/**init.pp
>>> class virtual {
>>>   @user { 'admin': ensure => present }
>>> }
>>>
>>> > cat $modulesdir/mailserver/**manifests/init.pp
>>> class mailserver {
>>>   realize(User['admin'])
>>>   # some more mailserver stuff...
>>> }
>>>
>>> > cat $modulesdir/webserver/**manifests/init.pp
>>> class webserver {
>>>   realize(User['admin'])
>>>   # some more webserver stuff...
>>> }
>>>
>>> > cat $manifestsdir/nodes.pp
>>>  node /<somenode>/ {
>>>   include virtual
>>>   include mailserver
>>>   include webserver
>>> }
>>>
>>>
>>> My question: How is that different, more convenient or more flexible
>>> than extracting that admin user into its own module? Like that:
>>>
>>> > cat $modulesdir/adminuser/**manifests/init.pp
>>> class adminuser {
>>>   user { 'admin': ensure => present }
>>> }
>>>
>>> > cat $modulesdir/mailserver/**manifests/init.pp
>>> class mailserver {
>>>    # some more mailserver stuff...
>>> }
>>>
>>> > cat $modulesdir/webserver/**manifests/init.pp
>>> class webserver {
>>>   # some more webserver stuff...
>>> }
>>>
>>> > cat $manifestsdir/nodes.pp
>>>  node /<somenode>/ {
>>>   include adminuser
>>>   include mailserver
>>>   include webserver
>>> }
>>>
>>>
>>> I guess I'm missing something here, or I'm using it wrong.
>>> Your help is highly appreciated,
>>>
>>
>>  In this simple case no, but think of a vinn diagram with overlapping
>> groups (such as user belonging to dbadmin/webadmin and two different teams
>> of dbadmin webadmin). You can easily realize virtual resource by tags, but
>> not so easy by splitting to class dbadmin/webadmin/db_and_**webadmin ...
>>
>> HTH,
>>
>> Nan
>>
>
> Do you mean something like this?
>
> > cat $modulesdir/virtual/manifests/**init.pp
> class virtual {
>   @user { ['a', 'b', 'c', 'd']: ensure => present }
> }
>
> > cat $modulesdir/mailserver/**manifests/init.pp
> class mailserver {
>   realize(User['a'], User['b'], User['c'])
>   # some more mailserver stuff...
> }
>
> > cat $modulesdir/webserver/**manifests/init.pp
> class webserver {
>   realize(User['b'], User['c'], User['d'])
>   # some more webserver stuff...
> }
>
> > cat $manifestsdir/nodes.pp
> node /<somenode>/ {
>   include virtual
>   include mailserver
>   include webserver
> }
>
>
Not quite, the realize function isn't that useful, you should use <| |>
instead. I'm going to use notify as an example:

class users {
  # admin with different responsibilities:
  @notify { 'a':
    tag => ['webadmin', 'dbadmin', 'prod', 'dev']
  }
  @notify { 'b':
    tag => ['dbadmin', 'prod', 'dev']
  }
  @notify { 'c':
    tag => ['webadmin','prod', 'dev']
  }
  # developers limited to dev environment:
  @notify { 'd':
    tag => ['dbadmin', 'dev']
  }
  @notify { 'e':
    tag => ['webadmin', 'dev',]
  }
}

class db ($env = 'prod') {
  include users
  Notify <| tag == 'dbadmin' and tag == $env |>
}

HTH,

Nan

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/puppet-users.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to