Ask Your Question

How to use databinding when multiple classes require the same parameters?

asked 2013-03-13 11:11:01 -0600

Stefan gravatar image

updated 2013-03-13 11:11:45 -0600

I am currently looking at hiera and data lookups for parameterized classes so I can define all parameters in hiera and can use the include statement in my node definitions. I have one question about it:

Let's assume I have an application that needs a MySQL Database as a storage backend. I have a class that creates the database and a database user with a password and grant the user access to the database. I also ship the configuration file of the application as a template and again I need the username and password so the application is able ... (more)

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2013-03-13 12:39:28 -0600

llowder gravatar image

I would go with number 1 for simplicity or number 2 for explicitness (which I really like personally). If you go with number 2, you can keep it DRY with the following YAML:

app::config::username: &AC_USERNAME mysusername
app::config::password: &AC_PASSWORD mypassword
app::database::username: *AC_USERNAME
app::database::password: *AC_PASSWORD

Another possibility is a modifed params class approach.

In params.pp list out everything as usual:

class app::params {
$username = myusername
$password = mypassword

and in init.pp:

class app(
  $username = $app::params::username,
  $password = $app::params::password,
  class { 'app:params': } ->
  class { 'app::config': } ->
  class { 'app::database': } ->


class ...
edit flag offensive delete link more


haven't thought about using references in the yaml file but I guess I go with your last suggestion but without the param class. This way I can configure everything ...(more)

Stefan gravatar imageStefan ( 2013-03-13 13:02:33 -0600 )edit

You can also do ) inherits app::params { instead of chaining class { 'app::params': }. Matter of preference I think.

Daenney gravatar imageDaenney ( 2013-03-13 14:26:58 -0600 )edit

Main reason to use inherit is if you wanted to override as only a subclass can override a param. But inheritance is somewhat error prone as it tends to not ...(more)

llowder gravatar imagellowder ( 2013-03-13 15:11:29 -0600 )edit

Your Answer

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

Add Answer

Question Tools


Asked: 2013-03-13 11:11:01 -0600

Seen: 724 times

Last updated: Mar 13 '13