On 2019-10-04 00:47, Jagga Soorma wrote:
Thanks Henrik.  However, changing my code to do the following still shows that warning:

--
class foo (
$nodetype = lookup('nodetype')
){
..blah..
}


You are missing that "automatic" in "automatic parameter lookup" means that it does this for you - no need to call lookup at all.

Simply do:

  class foo($nodetype) {
    # whatever
  }

And in your hiera (somewhere in a yaml file):

  foo::nodetype: this_is_the_nodetype

Then you can just do this:

  include foo

And it works.

Hope this helps clarify how it works.
- henrik

# 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)
Notice: Compiled catalog for node1.test.org in environment production in 0.03 seconds Notice: /Stage[main]/Foo/File[/tmp/hello]/ensure: defined content as '{md5}87e44021400167b9764b362083d182a1'
Notice: Applied catalog in 0.03 seconds
--

Am I missing something?


On Thursday, October 3, 2019 at 2:47:25 AM UTC-7, Henrik Lindberg wrote:

    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 <jag...@gmail.com
    <javascript:>> 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
    <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 <http://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/
    <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 <mailto:puppet-users+unsubscr...@googlegroups.com>. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/526e2c20-b9bb-4031-8eb7-4fceeb01def3%40googlegroups.com <https://groups.google.com/d/msgid/puppet-users/526e2c20-b9bb-4031-8eb7-4fceeb01def3%40googlegroups.com?utm_medium=email&utm_source=footer>.


--

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/qn6pev%24sfn%241%40blaine.gmane.org.

Reply via email to