Hi,
This follows on a bit from the previous thread 'trouble with hiera and 
puppet defines' [1]

Up to now I've had a large file of virtual resources and then enabled them 
on demand
on various services. The very standard.

@metric{'1234:
      one => 1
      two => [1,2]
}
@metric{'abcd':
      one => a, 
      two => [b,c]
}

and then somewhere realize potentially with an override <| title == 1234 |> 
{ one => 2  }

metric is something like 
define metric ($one, $two) {
   # do stuff.
}

Attempting to move the data of virtual resources above into hiera now  and 
a few questions.

metric1234:
     one: 1
     two:
           -'1'
           -'2'

metricabcd:
     one: a
     two:
          -'b'
          -'c'

I accept  to have to use that hierarchy rather than the perhaps more obvious
metric:
   1234: ...
    abcd: ...

since hiera can only select on the first level as the key?, i.e 
hiera(metic[1234]) or something is not posible is it?

To  realize in a manifest the following works:

$h = hiera_hash('metric4102')
$g = { '4102' => $h }
create_resources('lemon::metric',$g)

however what I would like to do is get the defaults from hiera within the 
defined resource so it becomes 
like the following which is incorrect but hopefully explains it.

metric{4102: one=> 'override'}

where metric is defined as 

define metric (hiera("lemon${title}") {
  # do stuff.
}

I can understand why that does not make sense, the define is only going to 
evaluated once and badly.

Only option I can think of is to override the paramters inside the define 
if they are non-sensical
defaults.

define metric(one=>'UNSET', two=>'UNSET) {

  $h = hiera("lemon${title}")
  if $one == 'UNSET' {
      $one = $h['one']
  }
  if $two == 'UNSET' {
      $two = $['two']
  }
}

but this is it a bit bizarre.

I am looking for a better way for a defined resource to get its defaults 
dynamically from hiera?

The motivation is that I probably only realize 20 of a potential > 1000 
resources 
on a particular host so dropping that yaml file data in a database backend 
to hiera would
make it easier.

I realize I can override with an earlier priority yaml file and hiera_hash 
but would like
the paramatized declaration to work also.

  Steve.

[1] https://groups.google.com/forum/?fromgroups#!topic/puppet-users/Ou9F3KdzqeE

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/puppet-users/-/dtpmuIJ-9h8J.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en.

Reply via email to