How to get Puppet ENC smart class parameter value in my puppet module

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:

$nis_servers = lookup(‘yp::bind::servers’, Array, ‘unique’, )

but that’s just not working. If I try without a default value it throws an error:

Function lookup() did not find a value for the name ‘yp::bind::servers’ on node mynode

I checked /opt/puppetlabs/puppet/cache/state/classes.txt and it lists:

yp
yp::config
yp::bind
yp::bind::install
yp::bind::config
yp::bind::service

and also the ENC preview for my node shows:

yp::bind:
domain: mydomain
servers:
- NIS slave server 1 IP
- NIS slave server 2 IP
service_enable: false
service_ensure: stopped

So what’s the right way to access the servers value from my class ?

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.

I tried getvar(yp::bind::servers) but doesn’t return anything (it doesn’t throw an error though).

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:

  1. Hiera.
    
  2. The current environment's data provider.
    
  3. 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.