bartavelle / language-puppet

A library to work with Puppet manifests, test them and eventually replace everything ruby.
BSD 3-Clause "New" or "Revised" License
51 stars 8 forks source link

Hiera hash are not merged between layers #277

Closed PierreR closed 5 years ago

PierreR commented 5 years ago

Given such a call to a hash named 'users' in a pp file $users = lookup('users', Hash, hash, {}), the hash will not be merged across hiera layers.

Within the same layer, the merge is working but between layers the merge will not happen.

bartavelle commented 5 years ago

Can you build me a minimal archive that demonstrates the problem? This looks like quite a bit of work to fix at first glance :/

PierreR commented 5 years ago

Here is a minimal case.

nix-shell:~/tmp/#277]$ puppetresources -p . -o default --hiera tests/hiera.yaml
ALERT: default: Scope stack :
ALERT: default:   class test
ALERT: default:   ::
ALERT: default:   ::
ALERT: default: Variables in local scope :
ALERT: default:   caller_module_name -> ::
ALERT: default:   module_name -> test
ALERT: default:   name -> test
ALERT: default:   title -> test
ALERT: default:   users -> {    test0 => {    home => /nonexistent,
uid  => 700}}
class {
  test: ./manifests/site.pp:6:3 default [Scope []]
      ;
}
stage {
  main: 1:1 default [Scope []]
      ;
}

I guess the problem is here: https://github.com/bartavelle/language-puppet/blob/master/src/Puppet/Interpreter/IO.hs#L105

We don't merge any values across layers in that function.

PierreR commented 5 years ago

Thinking about this a bit more, I wonder if there is a (immediate) need to merge from the module layer (because each key needs to be prefix by the module name).

As a first step we could just merge hashes from the global and the environment layers.

bartavelle commented 5 years ago

I will try to take a good look at this during the weekend.

PierreR commented 5 years ago

Thanks.

Forget about my previous comment ...

We do need to merge hashes across all layers. That said the most important is probably to merge hashes from the module layer and the environment layer.

Here is a new test case that is more representative.

bartavelle commented 5 years ago

I reworked the hiera part a bit, does that work better?

bartavelle commented 5 years ago

(just fixed the previous commit)

PierreR commented 5 years ago

Seems to work nicely so far.

Thanks !