On 2019-10-02 23:21, Jagga Soorma wrote:
Looks like I figured it out.  I was passing the hiera variable
incorrectly.  Changed from

passing in to class
String $nodetype,
to
$nodetype=hiera('nodetype')


Note that all functions starting with "hiera" are deprecated. Use the "lookup()" function instead. Google for the docs how to replace "hiera_include" with a call to "lookup()" and an iteration.

It is much better to use Automatic Parameter Lookup (APL) instead of doing explicit lookups. Your problem was that they key "nodetype" should have been "foo::nodetype" - that would make the correct binding for APL to work.

Best,
- henrik

that seems to have done the trick.

On Wed, Oct 2, 2019 at 1:39 PM Jagga Soorma <jagg...@gmail.com> wrote:

Hello,

I am testing out hiera and trying to pass some hiera values to a
module so that it can do specific tasks for a given node which does
not seem to be working.  Here is my setup:

--
# puppet lookup
--hiera_config=/root/test/puppetlabs/code/environments/production/hiera.yaml
nodetype
--- mgmt

# puppet apply 
--hiera_config=/root/test/puppetlabs/code/environments/production/hiera.yaml
--modulepath /root/test/puppetlabs/code/environments/production/modules
/root/test/puppetlabs/code/environments/production/manifests/site.pp
Warning: The function 'hiera_include' is deprecated in favor of using
'lookup'. See https://puppet.com/docs/puppet/6.9/deprecated_language.html
    (file & line not available)
Error: Evaluation Error: Error while evaluating a Function Call,
Class[Foo]: expects a value for parameter 'nodetype' (file:
/root/test/puppetlabs/code/environments/production/manifests/site.pp,
line: 2, column: 3) on node node1.test.org

# cat /root/test/puppetlabs/code/environments/production/hiera.yaml |
grep -v '#'
---
version: 5
defaults:
   datadir: data
   data_hash: yaml_data
hierarchy:
     - name: "Yaml heirarchy"
       data_hash: yaml_data
       paths:
         - "nodes/%{facts.networking.fqdn}.yaml"
         - "roles/common.yaml"
         - 'common.yaml'

# cat 
/root/test/puppetlabs/code/environments/production/data/nodes/node1.test.org.yaml
---
nodetype: 'mgmt'
classes:
  - foo

# cat /root/test/puppetlabs/code/environments/production/manifests/site.pp
node default {
   hiera_include('classes')
}

# cat 
/root/test/puppetlabs/code/environments/production/modules/foo/manifests/init.pp
class foo (
   String $nodetype,
){
   if $nodetype == 'mgmt' {
     file { "/tmp/hello":
       ensure => file,
       source => 'puppet:///modules/foo/hello.mgmt',
     }
   }
   elsif $nodetype == 'login' {
     file { '/tmp/hello':
       ensure => file,
       source => 'puppet:///modules/foo/hello.login',
     }
   }
}
--

Not sure what I am missing here, but any guidance would be helpful.
Also, let me know if there is a better way to tackle this.

Thanks,
-J



--

Visit my Blog "Puppet on the Edge"
http://puppet-on-the-edge.blogspot.se/

--
You received this message because you are subscribed to the Google Groups "Puppet 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to puppet-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/qn4g2t%24358l%241%40blaine.gmane.org.

Reply via email to