Puppet: System Administration Automated

Support

Ticket #1184 (closed defect: fixed)

Opened 8 months ago

Last modified 8 months ago

Autoloading definitions doesn't work, explicit import is required

Reported by: shadoi Assigned to: luke
Priority: normal Milestone:
Component: library Version: 0.24.4
Severity: normal Keywords: definition, autoload
Cc: marthag@mit.edu, francois@ctrlaltdel.ch Triage Stage: Accepted
Attached Patches: None Complexity: Unknown

Description

If you have a definition in a module like so:

modules/blah/manifests/thing.pp

That contains:

define blah::thing () { ... }

It won't get loaded when the module is. Even moving the contents of thing.pp into the init.pp for the module does not work. I haven't tested this on anything pre-0.24.x. I haven't been able to track it down in the code.

Change History

04/09/08 22:08:31 changed by marthag

  • cc set to marthag@mit.edu.

04/10/08 19:38:47 changed by arogge

I can confirm that issue. However if you include your definition in init.pp and load the module's main class somewhere in the manifest for the node that error only shows up sometimes.

04/10/08 22:24:29 changed by luke

I can't reproduce this.

Given this module:

define mymod::mydefine {
    notify { "main testing in $name": }
}

and this code:

mymod::mydefine { yay: }

I get this output:

luke@phage(0) $ test.pp --modulepath /Users/luke/.puppet/modules/main/
info: Loading fact test
info: Autoloaded module mymod
info: Autoloaded file mymod/mydefine from module mymod
notice: main testing in yay
[~]
luke@phage(0) $

Anything more you can give me as a hint as to what the problem might be?

04/10/08 22:24:37 changed by luke

  • stage changed from Unreviewed to Needs more info.

04/10/08 23:40:30 changed by arogge

This only seems to occur in client/server and (at least for me) only sometimes.

I'm using something like the following:

in my module's init.pp:

class nagios{ ... }
define nagios::check(...) {...}

in my site.pp:

import 'puppet.pp'

node basenode {
  include puppet
}

in puppet.pp:

class puppet {
  ...
  nagios::check { "puppet_freshness": }
  ...
}

in my node configuration:

node mynode inherits basenode {
  $nagios_parents = [ "parenthost" ]
  include nagios
}

I can see the problem only sometimes, but I think it happens for every host. I first guessed it would occur on the first recompile after puppetmaster reloads its files, but that's not the case. It just happens from time to time.

04/10/08 23:50:54 changed by ctrlaltdel

  • cc changed from marthag@mit.edu to marthag@mit.edu, francois@ctrlaltdel.ch.

I can confirm this, it happens in client/server mode when a client changes his environment.

A small example (C = puppetd, S = puppetmasterd)

C# puppetd -t --environment development
S# Compiled configuration for XXXX
C# puppetd -t --environment testing
S# Could not find resource type XXX on node XXX
C# puppetd -t --environment testing
S# Compiled configuration for XXXX
C# puppetd -t --environment development
S# Could not find resource type XXX on node XXX

This bug shows up each time the environment is modified, even by another client. This can explain the randomness reported by arogge.

04/11/08 00:15:50 changed by shadoi

Odd, I never see the definition autoload. I'm not using environments at all either.

04/11/08 00:22:03 changed by shadoi

Ok a little more info, I apparently wasn't calling the define correctly. After fixing that it correctly autoloads the file, but it's still unable to find the resource:

Apr 10 15:19:24 bdb-debvm1 puppetmasterd[2930]: importing '/etc/puppet/modules/blah/manifests/thing.pp'
Apr 10 15:19:24 bdb-debvm1 puppetmasterd[2930]: Autoloaded file blah/thing.pp from module blah
Apr 10 15:19:24 bdb-debvm1 puppetmasterd[2930]: Could not find resource type blah::thing at /etc/puppet/manifests/classes/base.pp:20 on node bdb-debvm1

04/11/08 05:49:20 changed by luke

  • owner changed from community to luke.
  • status changed from new to assigned.

The example code that arogge provided was the key -- the definition must be in a class, it can't be directly mentioned by the node.

Now that I've reproduced it, I'll track it down.

Just to make it clear, manually importing the file does fix the problem.

04/11/08 05:49:27 changed by luke

  • stage changed from Needs more info to Accepted.

04/11/08 06:19:35 changed by luke

  • status changed from assigned to closed.
  • resolution set to fixed.

Fixed in [2925ad1].

Note that I couldn't reproduce this in a unit test, but I've confirmed that I no longer can reproduce the problem.