modern data pattern?

43 views
Skip to first unread message

Guy Matz

unread,
Dec 17, 2014, 3:02:24 PM12/17/14
to puppet...@googlegroups.com
Hi!  I'm taking over someone's code and have found the following class signature - it's been abbreviated considerably; over 46 vars get used!!:

class showapp (
  $amqp_host,
  $amqp_password,
  $amqp_port,
  $amqp_user,
.
.
.

  $queue_service_host,
  $queue_service_port,
  $redis_host,
  $redis_port,
  ) 
It looks like they thought that any hiera vars that were going to be used in the template needed to be defined in the class signature (this isn't right, is it?).
these vars are defined in hiera and are needed to populate a template defined elsewhere in the class.    I'd rather not have to define every var in my manifest, e.g.:
$amqp_host = hiera(showapp::amqp_host)

I think I'd rather have a hash defined in hiera that I can pull into my class with one call, e.g.:
$showapp_data = hiera(showapp)
then use as a hash, e.g.
$showapp_data[amqp_host]

Is that the way to go?  Will it work?  Is there a better way?

If you're gotten this far, thank you, thank you, thank you!

Guy 

Byron Miller

unread,
Dec 17, 2014, 3:56:47 PM12/17/14
to puppet...@googlegroups.com
Guy,

The example you have like..

class showap(
   $amqp_host,
   .....
  )

Pattern is a "parameterized class" pattern. 

it's so you could have a site/node.pp or an ENC provide the parameters/values.

node yourserver {

  class { 'showap' : amqp_host => 'TRUE'}

}
or if you wish, hiera will do automagic lookups of class parameters


i tend to keep the parameterized class pattern since its fairly portable, works with hiera & enc's and once you've seen it, it does't look so scary..   46 parameters is a lot, but not unheard of..

-byron

Guy Matz

unread,
Dec 17, 2014, 4:48:15 PM12/17/14
to puppet...@googlegroups.com
So I can't use a hash?  I'm trying to make a general use parameterized class using a profile . . .  Can I do something like this so I only have to pass in the service name that I want to configure from my node definition:

class profiles::dropwizard (
  $dw_service = 'dw_service_UNDEFINED',
  $amqp_host = hiera($dw_service::amqp_host)
)

than my role would be:
class roles::showroom inherits roles::base {
  class { profiles::dropwizard:
                                dw_service => 'showroom',
   }
}

Hiera isn't able to find the above, and i've tried with varying curly braces.  Sorry if this is getting convoluted & out of scope.

--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/368c7156-cbcd-4165-a499-3d4a886e58cc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Guy Matz

unread,
Dec 17, 2014, 5:32:52 PM12/17/14
to puppet...@googlegroups.com
Working now!  If I quote the hiera call I can get dynamic lookups:
class profiles::dropwizard (
  $dw_service = 'dw_service_UNDEFINED',
  $amqp_host = hiera("${dw_service}::amqp_host")
)

Thanks!  
Reply all
Reply to author
Forward
0 new messages