Bug #1184
Autoloading definitions doesn't work, explicit import is required
| Status: | Closed | Start date: | ||
|---|---|---|---|---|
| Priority: | Normal | Due date: | ||
| Assignee: | % Done: | 0% |
||
| Category: | - | |||
| Target version: | - | |||
| Affected Puppet version: | 0.25.4 | Branch: | ||
| Keywords: | ||||
| Votes: | 0 |
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.
History
Updated by Andreas Rogge about 4 years ago
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.
Updated by Luke Kanies about 4 years ago
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?
Updated by Andreas Rogge about 4 years ago
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.
Updated by Francois Deppierraz about 4 years ago
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.
Updated by Blake Barnett about 4 years ago
Odd, I never see the definition autoload. I’m not using environments at all either.
Updated by Blake Barnett about 4 years ago
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 puppetmasterdr2930: importing '/etc/puppet/modules/blah/manifests/thing.pp' Apr 10 15:19:24 bdb-debvm1 puppetmasterdr2930: Autoloaded file blah/thing.pp from module blah Apr 10 15:19:24 bdb-debvm1 puppetmasterdr2930: Could not find resource type blah::thing at /etc/puppet/manifests/classes/base.pp:20 on node bdb-debvm1
Updated by Luke Kanies about 4 years ago
- Status changed from 1 to 2
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.
Updated by Luke Kanies about 4 years ago
- Status changed from 2 to Closed
- 7 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.
Updated by Justin Honold 10 months ago
Commented in the wrong place, ignore :)