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.)

Rob H
  • 629
  • 1
  • 7
  • 15
  • I think Hiera supports [YAML anchors and references](http://en.wikipedia.org/wiki/YAML#References). – Nic Aug 26 '13 at 05:37

2 Answers2

2

Using a & YAML anchor should work

database_server: &dbserver myoraclebox.example.com

class_a::database_server: *dbserver
class_b::database_server: *dbserver
dgorniak
  • 1
  • 2
Chris Montanaro
  • 830
  • 1
  • 7
  • 8
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.