Hi,
This seems to be simple but I can’t figure out how to get it to work:
I’ve created a puppet class to set a bunch of configuration items on my nodes. In that class I simply want to read a puppet ENC parameter value from another class. From what I found that should be something like:
You are using the wrong function. According to the Puppet docs, lookup explicitly looks data up in hiera, which you are not using.
You can use the getvar function instead, which can do what you are trying to achieve, e.g. getvar(yp::bind::servers).
Though a word of warning: Having this kind of cross-references and indirect dependencies between Puppet modules is very much discouraged and will most likely lead to some sort of headaches for future you.
The intended way to do this would be to use the roles and profiles pattern (although the official definition also discourages use of smart-class parameters on a role, but that’s just convention imo) and have the apropriate role/profile handle data being passed to the appropriate classes.
Looking a the Built-in function reference, lookup seems to be the right way:
Lookup
Uses the Puppet lookup system to retrieve a value for a given key. By default, this returns the first value found. When looking up a key, Puppet will search up to three tiers of data, in the following order:
Hiera.
The current environment's data provider.
The indicated module's data provider, if the key is of the form <MODULE NAME>::<SOMETHING>.
Hm, that’s curious, since I do have one use-case for this where getvar does work.
The only thing I could imagine is that these functions are parse-order dependant, which would mean that you can only access data from other classes if they were already processed by the parser (which would make it basically alphabetical ordering for all classes from the ENC). Though this is purely speculation on my part, I don’t know the inner workings of that well enough.