3

I'm using Hiera with Puppet and I want to pass the same parameter value to multiple classes without repeating it. Right now I've got (in Yaml):

---
class_a::database_server: myoraclebox.example.com
class_b::database_server: myoraclebox.example.com

This works, but how can I specify the server only once and still use Puppet's automatic parameter lookup? (I'd rather not embed an explicit Hiera lookup in my manifest, since that would couple it to Hiera.)

1

Using a & YAML anchor should work

database_server: &dbserver myoraclebox.example.com

class_a::database_server: *dbserver
class_b::database_server: *dbserver
0

Use the hiera() function to do a lookup as default values:

class class_a($database_server=hiera('database_server')){
}

class class_b($database_server=hiera('database_server')){
}

This uses the full Hiera machinery to do the lookup for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.