Define -> Class dependencies not respected

296 views
Skip to first unread message

Bruno Léon

unread,
Jun 13, 2012, 7:22:06 PM6/13/12
to puppet...@googlegroups.com
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

Felix Frank

unread,
Jun 14, 2012, 3:39:00 AM6/14/12
to puppet...@googlegroups.com
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

Nan Liu

unread,
Jun 14, 2012, 12:39:19 PM6/14/12
to puppet...@googlegroups.com
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

Bruno Leon

unread,
Jun 21, 2012, 12:59:57 PM6/21/12
to puppet...@googlegroups.com


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
 
Reply all
Reply to author
Forward
0 new messages