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