Bruno Léon
2012-Jun-13 23:22 UTC
[Puppet Users] Define -> Class dependencies not respected
Hello, I''m encountering an issue which I think is a bug, but I want to propose it here before filing it for good @puppetlabs, and be sure it''s not just a misunderstanding. Actually, I often use a construction where a "main" class would include some small others that build a complete service (install, config, service ) Relationship are given (and respected) in the main class between those subclasses. However, I found out that is a defined type is stating that it requires the main class, this won''t mean it requires the subclasses. Here is an example, ran on Ubuntu with the package "ldap". ###################" define aaaa () { Class[ ''test''] -> Aaaa[ $name ] file { ''/etc/slapd.d/define'': ensure => file, content => ''define'', } } class test { Class[ ''install'' ] -> Class[ ''config''] include install include config } class install { package { ''slapd'': ensure => ''present'', } } class config { file { ''/etc/slapd.d/config'': ensure => file, content => ''config'', } } node default { aaaa { ''test'': } include test } ################ notice: /Stage[main]//Node[default]/Aaaa[test]/File[/etc/slapd.d/define]/ensure: current_value absent, should be file (noop) notice: Aaaa[test]: Would have triggered ''refresh'' from 1 events notice: Node[default]: Would have triggered ''refresh'' from 1 events notice: /Stage[main]/Install/Package[slapd]/ensure: current_value purged, should be present (noop) notice: Class[Install]: Would have triggered ''refresh'' from 1 events notice: /Stage[main]/Config/File[/etc/slapd.d/config]/ensure: current_value absent, should be file (noop) notice: Class[Config]: Would have triggered ''refresh'' from 1 events notice: Class[Main]: Would have triggered ''refresh'' from 1 events notice: Stage[main]: Would have triggered ''refresh'' from 3 events notice: Finished catalog run in 0.18 seconds As we can see, the define Aaaa[test] is created before the class, and in this case Puppet would fail because the folder /etc/slapd.d/ would not exist before the file "/etc/slapd.d/define" is created in it. This could of course be fixed by requiring the subclass "install" directly, but I think that is unexpected. I hope some will be able to shine my lights on this Puppet behaviour. Thanks -- Bruno Léon -- 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.
Felix Frank
2012-Jun-14 07:39 UTC
Re: [Puppet Users] Define -> Class dependencies not respected
Hi, On 06/14/2012 01:22 AM, Bruno Léon wrote:> Hello, > > I''m encountering an issue which I think is a bug, but I want to propose > it here before filing it for good @puppetlabs, > and be sure it''s not just a misunderstanding. > > Actually, I often use a construction where a "main" class would include > some small others that build a complete > service (install, config, service ) > Relationship are given (and respected) in the main class between those > subclasses. > > However, I found out that is a defined type is stating that it requires > the main class, this won''t mean it requires the subclasses.yes, it''s a minor PITa, read on.> Here is an example, ran on Ubuntu with the package "ldap". > > ###################" > define aaaa () { > Class[ ''test''] -> Aaaa[ $name ] > file { ''/etc/slapd.d/define'': > ensure => file, > content => ''define'', > } > } ... > notice: > /Stage[main]//Node[default]/Aaaa[test]/File[/etc/slapd.d/define]/ensure: > current_value absent, should be file (noop) > notice: Aaaa[test]: Would have triggered ''refresh'' from 1 events > notice: Node[default]: Would have triggered ''refresh'' from 1 events > notice: /Stage[main]/Install/Package[slapd]/ensure: current_value > purged, should be present (noop) > notice: Class[Install]: Would have triggered ''refresh'' from 1 events > notice: /Stage[main]/Config/File[/etc/slapd.d/config]/ensure: > current_value absent, should be file (noop) > notice: Class[Config]: Would have triggered ''refresh'' from 1 events > notice: Class[Main]: Would have triggered ''refresh'' from 1 events > notice: Stage[main]: Would have triggered ''refresh'' from 3 events > notice: Finished catalog run in 0.18 seconds > > As we can see, the define Aaaa[test] is created before the class, and in > this case Puppet would fail > because the folder /etc/slapd.d/ would not exist before the file > "/etc/slapd.d/define" is created in it. > > This could of course be fixed by requiring the subclass "install" > directly, but I think that is unexpected. > > I hope some will be able to shine my lights on this Puppet behaviour.As a matter of fact, I *have* opened http://projects.puppetlabs.com/issues/7928 for this, but it''s not easily resolved. This is a design problem. Basically, if you want your defined type to behave like classes wrt. meta parameters, you need to add them to each resource in your defined type like this: define aaaa () { Class[ ''test''] -> Aaaa[ $name ] file { ''/etc/slapd.d/define'': ensure => file, content => ''define'', require => $require, before => $before, notify => $notify, ... } } It''s highly impractical, but on the other hand, if puppet were to include these automatically, this would raise other questions such as - what if I want a specific resource to *not* respect the global require - how are additional metaparameters of inner resources treated etc. Worst thing is, I guess, that changing how this works will break existing manifests, so I think we''ll have to learn to deal. Cheers, Felix -- 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.
Nan Liu
2012-Jun-14 16:39 UTC
Re: [Puppet Users] Define -> Class dependencies not respected
On Wed, Jun 13, 2012 at 4:22 PM, Bruno Léon <nonolemono@gmail.com> wrote:> I''m encountering an issue which I think is a bug, but I want to propose it > here before filing it for good @puppetlabs, > and be sure it''s not just a misunderstanding. > > Actually, I often use a construction where a "main" class would include some > small others that build a complete > service (install, config, service ) > Relationship are given (and respected) in the main class between those > subclasses. > > However, I found out that is a defined type is stating that it requires the > main class, this won''t mean it requires the subclasses. > > Here is an example, ran on Ubuntu with the package "ldap". > > ###################" > define aaaa () { > Class[ ''test''] -> Aaaa[ $name ] > file { ''/etc/slapd.d/define'': > ensure => file, > content => ''define'', > } > } > > class test { > Class[ ''install'' ] -> Class[ ''config''] > include install > include config > } > > class install { > package { ''slapd'': > ensure => ''present'', > } > } > > class config { > file { ''/etc/slapd.d/config'': > ensure => file, > content => ''config'', > } > } > > node default { > aaaa { ''test'': } > include test > } > ################ > > notice: > /Stage[main]//Node[default]/Aaaa[test]/File[/etc/slapd.d/define]/ensure: > current_value absent, should be file (noop) > notice: Aaaa[test]: Would have triggered ''refresh'' from 1 events > notice: Node[default]: Would have triggered ''refresh'' from 1 events > notice: /Stage[main]/Install/Package[slapd]/ensure: current_value purged, > should be present (noop) > notice: Class[Install]: Would have triggered ''refresh'' from 1 events > notice: /Stage[main]/Config/File[/etc/slapd.d/config]/ensure: current_value > absent, should be file (noop) > notice: Class[Config]: Would have triggered ''refresh'' from 1 events > notice: Class[Main]: Would have triggered ''refresh'' from 1 events > notice: Stage[main]: Would have triggered ''refresh'' from 3 events > notice: Finished catalog run in 0.18 seconds > > As we can see, the define Aaaa[test] is created before the class, and in > this case Puppet would fail > because the folder /etc/slapd.d/ would not exist before the file > "/etc/slapd.d/define" is created in it. > > This could of course be fixed by requiring the subclass "install" directly, > but I think that is unexpected. > > I hope some will be able to shine my lights on this Puppet behaviour.This is a class containment problem, and the reason why anchor resource type exists in puppetlabs-stdlib. Here''s the ticket: http://projects.puppetlabs.com/issues/8040 Thanks, Nan -- 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.
Bruno Leon
2012-Jun-21 16:59 UTC
Re: [Puppet Users] Define -> Class dependencies not respected
> > This is a class containment problem, and the reason why anchor > resource type exists in puppetlabs-stdlib. Here''s the ticket: > http://projects.puppetlabs.com/issues/8040 > > Thanks, > > Nan >Thanks for the replies, I forgot I was already tracking this issue actually. Let''s hope the "contain" "require" proposed fix is released one day. Bruno -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/WS7sNWhlU40J. 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.