Christian Flamm
2013-Jul-12 14:45 UTC
[Puppet Users] What''s the benefit of Virtual Resources?
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.ppclass virtual { @user { ''admin'': ensure => present } }> cat $modulesdir/mailserver/manifests/init.ppclass mailserver { realize(User[''admin'']) # some more mailserver stuff... }> cat $modulesdir/webserver/manifests/init.ppclass webserver { realize(User[''admin'']) # some more webserver stuff... }> cat $manifestsdir/nodes.ppnode /<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.ppclass adminuser { user { ''admin'': ensure => present } }> cat $modulesdir/mailserver/manifests/init.ppclass mailserver { # some more mailserver stuff... }> cat $modulesdir/webserver/manifests/init.ppclass webserver { # some more webserver stuff... }> cat $manifestsdir/nodes.ppnode /<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, thanks in advance, Christian -- 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+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.
Matthew Burgess
2013-Jul-12 14:58 UTC
Re: [Puppet Users] What''s the benefit of Virtual Resources?
On 12 July 2013 15:45, Christian Flamm <christian.le.flamm@gmail.com> wrote:> > My question: How is that different, more convenient or more flexible than > extracting that admin user into its own module? >I guess the main advantage is one of containing the knowledge of that user into the thing that needs to know about it. i.e. the mailserver and webserver modules know that they need that user in order to manage other resources (e.g. install a package/start a service). By splitting it out the way you have in your second example, something/someone else needs to know/remember that because node x has module y declared, it also needs module z to be declared too. That fact is really internal to the other two modules, so shouldn''t need to be exposed at the node level. I guess the corollary is; if your webserver module declares a package and a service resource, why don''t you split those out into separate modules? You probably wouldn''t, right, because they''re closely related? Well, nor should you split the user out into a separate module. If it so happens that 2 modules need to ensure a particular resource is declared, doing so via the virtual resource functionality is a reasonable way of doing that. Regards, Matt. -- 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+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.
Nan Liu
2013-Jul-12 15:03 UTC
Re: [Puppet Users] What''s the benefit of Virtual Resources?
On Fri, Jul 12, 2013 at 7:45 AM, Christian Flamm < christian.le.flamm@gmail.com> 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 -- 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+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.
Christian Flamm
2013-Jul-12 15:11 UTC
Re: [Puppet Users] What''s the benefit of Virtual Resources?
Am Freitag, 12. Juli 2013 17:03:11 UTC+2 schrieb Nan Liu:> > On Fri, Jul 12, 2013 at 7:45 AM, Christian Flamm <christian...@gmail.com<javascript:> > > 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.ppclass virtual { @user { [''a'', ''b'', ''c'', ''d'']: ensure => present } }> cat $modulesdir/mailserver/manifests/init.ppclass mailserver { realize(User[''a''], User[''b''], User[''c'']) # some more mailserver stuff... }> cat $modulesdir/webserver/manifests/init.ppclass webserver { realize(User[''b''], User[''c''], User[''d'']) # some more webserver stuff... }> cat $manifestsdir/nodes.ppnode /<somenode>/ { include virtual include mailserver include webserver } -- 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+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.
Nan Liu
2013-Jul-12 16:09 UTC
Re: [Puppet Users] What''s the benefit of Virtual Resources?
On Fri, Jul 12, 2013 at 8:11 AM, Christian Flamm < christian.le.flamm@gmail.com> 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 <christian...@gmail.com>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 puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.
jcbollinger
2013-Jul-12 22:12 UTC
Re: [Puppet Users] What''s the benefit of Virtual Resources?
On Friday, July 12, 2013 11:09:49 AM UTC-5, Nan Liu wrote:> > On Fri, Jul 12, 2013 at 8:11 AM, Christian Flamm <christian...@gmail.com<javascript:> > > wrote: > >> >> >> 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... >> } >> >> > Not quite, the realize function isn''t that useful, you should use <| |> > instead. >Well *I* like the realize function. Christian''s example is a perfectly good demonstration of one of the ways virtual resources can be useful. To be sure, collections and tags play well with virtual resources, and the combination can be pretty slick, but please don''t throw realize under the bus just yet. 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+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.