Ask Your Question
0

Complex variable in Hiera

asked 2014-08-14 14:58:46 -0500

ssmi4th gravatar image

I have a module with a variable $servers defined as:

class scheduler::params {

$servers    = {
    'Server 1' => 'http://localhost:9080',
    'Server 2' => 'http://localhost:9081',
    'Server 3' => 'http://localhost:9082'
}

}

that completes a template file:

servers = [ <%= @servers.map { |name,url| "[ name: '" + name + "', url: '" + url + "' ]" }.join(',') %> ]

I want to be able to customize this in a yaml config file, but configurations I've tried have failed, e.g., :

module::submodule::servers: [ 'Server 1 : http://localhost:10080, Server 2 : http://localhost:10081, Server 3 : http://localhost:10082']

I've done this with double quotes on the servers, using the => instead of the : -- not sure what to do next.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2014-08-15 04:20:17 -0500

It's not an array its a hash. Everything in hiera is essentially a hash. Try something like this.

module::submodule::servers:
  'Server 1': 'http://localhost:10080'
  'Server 2': 'http://localhost:10081'
  ...
  ...

You can always double check in ruby using a ruby hash

require 'yaml'

hsh = { 'module::submodule::servers' => { 'Server 1' => 'http://localhost:10080', 'Server 2' => 'http://localhost10081' } }

irb(main):017:0> puts hsh.to_yaml
  ---
  module::submodule::servers:
    Server 1: http://localhost:10080
    Server 2: http://localhost:10081

Hope this helps

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

Stats

Asked: 2014-08-14 14:58:46 -0500

Seen: 137 times

Last updated: Aug 15 '14