Ask Your Question
1

Parametrized Classes with Hiera_Include("Classes")

asked 2013-10-10 11:29:27 -0500

louis gravatar image

Is it possible to assign parameter values to classes with the hiera_include function on the site.pp?

Seems like hiera_include expects an array and then needs to parse each item as a hash...

http://docs.puppetlabs.com/hiera/1/puppet.html

site.pp

hiera_include('classes')

defaults.yaml

---
classes:
  - test::variable: "5.0"

test class

class test ($variable = "default") {

 notice("This is the variable value: ${variable}")

 file {'/tmp/variable.txt':
    ensure  => present,
    content => $variable
  }

}

Exception...

Error: Could not retrieve catalog from remote server: Error 400 on SERVER: undefined method `downcase' for {"test::variable"=>"5.0"}:Hash at /etc/puppetlabs/puppet/manifests ...
(more)
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2013-10-10 14:53:19 -0500

Ancillas gravatar image

If you're on Puppet 3.0+, DataBindings will already search your hiera catalog for test::variable.

I just tested this on Puppet 3.2, and it worked just fine. Here are my files.

common.yaml

---
classes:
 - test

test::variable: 'pew pew'

test.pp

hiera_include('classes')

class test (
  $variable = 'default'
) {
  notice("This is the variable value: ${variable}")

  file {'/tmp/variable.txt':
     ensure  => present,
     content => "${variable}",
   }
}

If you have Puppet 2.7-, you'll need to fake DataBindings like so.

test.pp

hiera_include('classes')

class test (
  $variable = hiera('test::variable','default')
) {
  notice("This is the variable value: ${variable}")

  file {'/tmp/variable ...
(more)
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2013-10-10 11:29:27 -0500

Seen: 6,427 times

Last updated: Oct 10 '13