Matthew Barr
2013-Apr-18 20:44 UTC
[Puppet Users] Scoping of default types & dependency loops
I''m seeing an interesting dependency issue, based on scoping of default types. Using 3.1.1 & aware of http://docs.puppetlabs.com/guides/scope_and_puppet.html#declare-resource-defaults-per-file Our mongo::repos class is inheriting the File default that is set in the mongo class. This leads to a dependency circle, since we''re using the default to set a require of a package for every file. :I would have thought the scoping rules would have prevented that from happening. (I''ve cut most of the unnecessary stuff.) The 2 easiest ways to fix this would be to use yumrepo in the repos function, or to just put the require parameter on each file, and skip the default. I''m more interested in why it produced the loop. #Notes: repos is a defined class that places a file into the correct place.. It isn''t using the yum_repo type for this, yet. class mongo::repos { repos{"10gen":} } class mongo ($repl_set=undef) { class {''mongo::repos'': stage => first,} package { "mongo20-10gen-server": ensure => installed, } File { require => Package[''mongo20-10gen-server''] } file { ''/etc/init.d/mongod'': ensure => present, mode => 755, owner => ''root'', group => ''root'', source => ''puppet:///modules/mongo/mongod'', require => Package[''mongo20-10gen-server'']; } } Matthew Barr Technical Architect E: mbarr@snap-interactive.com AIM: matthewbarr1 c: (646) 727-0535 -- 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?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
jcbollinger
2013-Apr-19 13:21 UTC
[Puppet Users] Re: Scoping of default types & dependency loops
On Thursday, April 18, 2013 3:44:34 PM UTC-5, Matthew Barr wrote:> > I''m seeing an interesting dependency issue, based on scoping of default > types. > Using 3.1.1 & aware of > http://docs.puppetlabs.com/guides/scope_and_puppet.html#declare-resource-defaults-per-file > > Our mongo::repos class is inheriting the File default that is set in the > mongo class. > This leads to a dependency circle, since we''re using the default to set a > require of a package for every file. > > :I would have thought the scoping rules would have prevented that from > happening. >As far as I am aware, resource defaults still affect the dynamic scope in which they are declared, just as they always have done. The guide to which you referred seems to say that, too. That means that the defaults you declare in class ''mongo'' apply to all resources declared in that class and in any classes declared by that class, recursively, modulo parse-order issues where the same class is declared in different places. In your particular case, that means the File defaults you declare in class ''mongo'' apply in class mongo::repos (which is declared by class mongo) and within the defined type instances declared therein.> > (I''ve cut most of the unnecessary stuff.) > > The 2 easiest ways to fix this would be to use yumrepo in the repos > function, or to just put the require parameter on each file, and skip > the default. > > I''m more interested in why it produced the loop. > > > #Notes: repos is a defined class that places a file into the correct place.. It isn''t using the yum_repo type for this, yet. > > class mongo::repos { > repos{"10gen":} > >You really should use the fully-qualified name of that defined type. I suppose it must be "mongo::repos::repos". Aside from being safer, it would be much clearer. Anyway, If you don''t want class ''mongo''s file defaults to apply in this scope then you could try overriding them here: File { require => undef } Alternatively, the file resource(s) declared by mongo::repos::repos can do the same thing individually.> } > > class mongo ($repl_set=undef) { > class {''mongo::repos'': stage => first,} > > package { "mongo20-10gen-server": > ensure => installed, > } > > File { > require => Package[''mongo20-10gen-server''] > } > > file { > ''/etc/init.d/mongod'': > ensure => present, > mode => 755, > owner => ''root'', > group => ''root'', > source => ''puppet:///modules/mongo/mongod'', > require => Package[''mongo20-10gen-server'']; > } > } > > >Best, though, might be to refactor class ''mongo'' so that the scope of the resource defaults does not include class mongo::repos in the first place. For example: class mongo($repl_set = undef) { class { ''mongo::repos'': stage => ''first'' } class { ''mongo::everything_else'': } } class mongo::everything_else { File { require => Package[''mongo20-10gen-server''] } ... } 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?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Matthew Barr
2013-Apr-19 15:06 UTC
Re: [Puppet Users] Scoping of default types & dependency loops
> As far as I am aware, resource defaults still affect the dynamic scope in which they are declared, just as they always have done. The guide to which you referred seems to say that, too. That means that the defaults you declare in class ''mongo'' apply to all resources declared in that class and in any classes declared by that class, recursively, modulo parse-order issues where the same class is declared in different places. > > In your particular case, that means the File defaults you declare in class ''mongo'' apply in class mongo::repos (which is declared by class mongo) and within the defined type instances declared therein.That''s what I was figuring must be happening. As dig deeper, I keep trying to get to a better place in my head w/ regard to scoping. It''s… interesting sometimes :)> > > class mongo::repos { > repos{"10gen":} } > You really should use the fully-qualified name of that defined type. I suppose it must be "mongo::repos::repos". Aside from being safer, it would be much clearer.Actually, the defined type is in it''s own module, repos. It''s the only thing in there, and thus, this would be it''s FQN, wouldn''t it ? Class mongo::repos only exists to call it, and move the repos{"10gen":} into another stage. I couldn''t see a way to do it any other way when I initially set this up. That was the entirety of the mongo::repos class.> Anyway, If you don''t want class ''mongo''s file defaults to apply in this scope then you could try overriding them here: > > File { > require => undef > } > > Alternatively, the file resource(s) declared by mongo::repos::repos can do the same thing individually. > > > Best, though, might be to refactor class ''mongo'' so that the scope of the resource defaults does not include class mongo::repos in the first place. For example: > > class mongo($repl_set = undef) { > class { ''mongo::repos'': stage => ''first'' } > class { ''mongo::everything_else'': } > } >And that''s the way that feels right. The undef option is hacky. The refactor seems to be the more clear & elegant. So in summary: 3 total hacks, 1 better answer. Thanks! -- 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?hl=en. For more options, visit https://groups.google.com/groups/opt_out.