Jon Stanley
2009-Sep-15 02:07 UTC
[Puppet Users] Question on proper use of virtual resources
I''m attempting to use virtual resources to get around multiple definition errors, but it doesn''t seem to be working. I need to create a directory structure like "/apps/siteA/instance_1/resin" and "/apps/siteA/instance_2/resin". In reality it''s a little more complex, because there are multiple sites running on a given node. Anyhow, here''s how I''ve defined it: define resin::instance( $site_alias, $env_alias, $instance, $host_alias, $resin_ver, $java_ver ) { include resin::base @file { "/apps/runtime/$site_alias": owner => cnp, group => cnp-admin, mode => 0755, require => File["/apps/runtime"], ensure => directory; "/apps/runtime/$site_alias/$env_alias": owner => cnp, group => cnp-admin, mode => 0755, require => File["/apps/runtime/$site_alias"], ensure => directory; "/apps/runtime/$site_alias/$env_alias/resin/${host_alias}_${env_alias}_${instance}": owner => cnp, group => cnp-admin, mode => 0755, require => File["/apps/runtime/$site_alias/$env_alias"], ensure => directory; } realize File["/apps/runtime/$site_alias"] realize File["/apps/runtime/$site_alias/$env_alias"] realize File["/apps/runtime/$site_alias/$env_alias/resin/${host_alias}_${env_alias}_${instance}"] } I was thinking that using the virtual resource in the definition would get around the errors, but it doesn''t seem to have: err: Could not retrieve catalog: Puppet::Parser::AST::Resource failed with error ArgumentError: Duplicate definition: File[/apps/runtime/gq] is already defined in file /var/lib/puppet/git/modules/resin/manifests/init.pp at line 40; cannot redefine at /var/lib/puppet/git/modules/resin/manifests/init.pp:40 on node s602250nj3el563.uspswy6.savvis.net What''s another approach to doing this? The end goal is having one simple call to define an instance, not mattering if the site is known or unknown (so a bunch of classes to include wouldn''t be scalable here), or if it''s on that machine or not - i.e. from one simple resin::instance call, I should be able to have a functional instance. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en -~----------~----~----~----~------~----~------~--~---
I run into this problem often. I usually encounter it trying to make independent modules A and B, which both depend on some directory. Or even just around realizing users, I''d love to not worry about realizing the same user twice. Anyhow, it''s imperfect, but you can check if something is defined, and if it''s not then define it. seph Jon Stanley <jonstanley@gmail.com> writes:> I''m attempting to use virtual resources to get around multiple > definition errors, but it doesn''t seem to be working. I need to > create a directory structure like "/apps/siteA/instance_1/resin" and > "/apps/siteA/instance_2/resin". In reality it''s a little more complex, > because there are multiple sites running on a given node. Anyhow, > here''s how I''ve defined it: > > define resin::instance( > $site_alias, > $env_alias, > $instance, > $host_alias, > $resin_ver, > $java_ver > ) { > include resin::base > @file { "/apps/runtime/$site_alias": > owner => cnp, > group => cnp-admin, > mode => 0755, > require => File["/apps/runtime"], > ensure => directory; > "/apps/runtime/$site_alias/$env_alias": > owner => cnp, > group => cnp-admin, > mode => 0755, > require => File["/apps/runtime/$site_alias"], > ensure => directory; > "/apps/runtime/$site_alias/$env_alias/resin/${host_alias}_${env_alias}_${instance}": > owner => cnp, > group => cnp-admin, > mode => 0755, > require => File["/apps/runtime/$site_alias/$env_alias"], > ensure => directory; > } > realize File["/apps/runtime/$site_alias"] > realize File["/apps/runtime/$site_alias/$env_alias"] > realize File["/apps/runtime/$site_alias/$env_alias/resin/${host_alias}_${env_alias}_${instance}"] > > } > > I was thinking that using the virtual resource in the definition would > get around the errors, but it doesn''t seem to have: > > err: Could not retrieve catalog: Puppet::Parser::AST::Resource failed > with error ArgumentError: Duplicate definition: File[/apps/runtime/gq] > is already defined in file > /var/lib/puppet/git/modules/resin/manifests/init.pp at line 40; cannot > redefine at /var/lib/puppet/git/modules/resin/manifests/init.pp:40 on > node s602250nj3el563.uspswy6.savvis.net > > What''s another approach to doing this? The end goal is having one > simple call to define an instance, not mattering if the site is known > or unknown (so a bunch of classes to include wouldn''t be scalable > here), or if it''s on that machine or not - i.e. from one simple > resin::instance call, I should be able to have a functional instance. > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en -~----------~----~----~----~------~----~------~--~---
Jon Stanley
2009-Sep-15 13:37 UTC
[Puppet Users] Re: Question on proper use of virtual resources
On Tue, Sep 15, 2009 at 8:30 AM, seph <seph@directionless.org> wrote:> I''d love to not worry about realizing > the same user twice.I thought that was the whole point of virtual resources, though - you can realize the same resource as many times as you''d like and only end up with one copy of it. I''m thinking the duplicate definition error *may* be the result of defining the same virtual resource twice - i.e. if I somehow define it outside the scope of the define, and realize it however many times is needed, then it''s all good. Could someone with knowledge in this area correct me if I''m wrong, and provide a pointer to how to "define something outside a define" that''s not a static resource? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en -~----------~----~----~----~------~----~------~--~---
David Schmitt
2009-Sep-15 13:41 UTC
[Puppet Users] Re: Question on proper use of virtual resources
Jon Stanley wrote:> On Tue, Sep 15, 2009 at 8:30 AM, seph <seph@directionless.org> wrote: > >> I''d love to not worry about realizing >> the same user twice. > > I thought that was the whole point of virtual resources, though - you > can realize the same resource as many times as you''d like and only end > up with one copy of it. > > I''m thinking the duplicate definition error *may* be the result of > defining the same virtual resource twice - i.e. if I somehow define it > outside the scope of the define, and realize it however many times is > needed, then it''s all good. > > Could someone with knowledge in this area correct me if I''m wrong, and > provide a pointer to how to "define something outside a define" that''s > not a static resource? >My typical pattern in that case looks like this: class required_stuff { file { "/etc/something": ... } } define something() { include required_stuff ... } Regards, DavidS --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en -~----------~----~----~----~------~----~------~--~---
Jon Stanley
2009-Sep-15 13:48 UTC
[Puppet Users] Re: Question on proper use of virtual resources
On Tue, Sep 15, 2009 at 9:41 AM, David Schmitt <david@dasz.at> wrote:> My typical pattern in that case looks like this:Right, but what if the "something" in /etc/something is unknown and you need to define multiple things under /etc/something (say /etc/something/1 and /etc/something/2)? In the end, there''s only going to be about 30 sites. It *could* be statically defined. But that''s *really* hard to scale. And then I have the question of does include $something actually work in a define? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en -~----------~----~----~----~------~----~------~--~---
David Schmitt
2009-Sep-15 13:55 UTC
[Puppet Users] Re: Question on proper use of virtual resources
Jon Stanley wrote:> On Tue, Sep 15, 2009 at 9:41 AM, David Schmitt <david@dasz.at> wrote: > >> My typical pattern in that case looks like this: > > Right, but what if the "something" in /etc/something is unknown and > you need to define multiple things under /etc/something (say > /etc/something/1 and /etc/something/2)?> In the end, there''s only going to be about 30 sites. It *could* be > statically defined. But that''s *really* hard to scale.Either it is common to all defines, then it goes into the class or it is per define, then it doesn''t collide.> And then I have the question of does include $something actually work > in a define?Yes. Both with and without $: define test() { include something include "something::${name}" } test { foo: } will include "something" and "something::foo", but I''d advise against such hacks except for the most desperate cases. Regards, DavidS --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en -~----------~----~----~----~------~----~------~--~---
Jon Stanley
2009-Sep-15 16:08 UTC
[Puppet Users] Re: Question on proper use of virtual resources
On Tue, Sep 15, 2009 at 9:55 AM, David Schmitt <david@dasz.at> wrote:> will include "something" and "something::foo", but I''d advise against > such hacks except for the most desperate cases.So for the benefit of the list, I figured out that the problem was not *using* the virtual resource multiple times, it was with defining it multiple times. What I wound up doing was making a new class of foo::files, which contains only virtual resources of all of the combinations and permutations of the directories that I''ll need (this is going to get very long and very ugly, which is what I was hoping to avoid). Then I include this mega-class, and in the define, realize the directories that I need out of that class. I just wish there were a better way, but this seems the least hackish. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en -~----------~----~----~----~------~----~------~--~---
Jon Stanley <jonstanley@gmail.com> writes:> So for the benefit of the list, I figured out that the problem was not > *using* the virtual resource multiple times, it was with defining it > multiple times.Huh. Indeed. I swear it used to be different. Ah well, either it changed when I wasn''t looking, or I''m confused. Either way, this is awesome. seph --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en -~----------~----~----~----~------~----~------~--~---