Ask Your Question
0

Simple top-level yaml hash not merging

asked 2017-11-30 12:37:27 -0600

Supermathie gravatar image

I have the following hiera definitions:

# hiera.yaml
:backends:
  - yaml

:yaml:
  :datadir: /home/supermathie/puppettest

:hierarchy:
  - local
  - global

# global.yaml
containers:
  auth-proxy:
    image: 'devel/auth-proxy'
  kibana:
    image: 'devel/kibana'
  elasticsearch:
    image: 'devel/elasticsearch'
  logstash:
    image: 'devel/logstash'

# local.yaml
containers:
  kibana:
    image: 'devel/kibana-local'

I'm trying to override a single item in the containers hash, but I don't understand why it isn't merging the contents from both yaml files - everything I've read so far says that this is supposed to work:

$ puppet apply --hiera_config hiera.yaml <<<"notice(hiera('containers'))"
Notice: Scope(Class[main]): {"kibana"=>{"image"=>"devel/kibana-local"}}

Expected output:

$ puppet apply --hiera_config hiera.yaml <<<"notice(hiera('containers'))"
Notice: Scope(Class[main]): {"auth-proxy"=>{"image"=>"devel/auth-proxy"}, "kibana"=>{"image"=>"devel/kibana-local"}, "elasticsearch"=>{"image"=>"devel/elasticsearch"}, "logstash"=>{"image"=>"devel/logstash"}}

What's going wrong?


Versions:

$ puppet -V
3.8.7
$ hiera -V
1.3.4
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2017-12-03 12:03:10 -0600

jorhett gravatar image

updated 2017-12-03 12:06:02 -0600

First of all, you're using a hiera configuration format and hiera function calls from a version of Puppet that's end-of-life for a year now. You really should upgrade to Hiera v5 and use the lookup() function: https://puppet.com/docs/puppet/5.3/hi...

But the issue here is that you haven't requested a merge, so you are getting "first" lookup. In new terms, you are doing this:

lookup('containers', {merge => first})

When you need to request a merge type. Since you want to override a value within a hash, you'll need a 'deep' merge:

lookup('containers', {merge => deep})

If you forced to use an EOL version of puppet, you can get the merge behavior by using hiera_hash('containers') and putting the following in your hiera.yaml. :merge_behavior: deep

The old Hiera the merge parameter is global, not configurable on a per-lookup basis so all hiera_hash calls will be merged deep. This is a good reason to upgrade!

It sounds like you are new to Puppet. 3.8.7 is the dead end run of a lot of history you don't need to be held back by. Get the Puppet Development Kit and work with a better designed, lessons learned version of Puppet.

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

1 follower

Stats

Asked: 2017-11-30 12:37:27 -0600

Seen: 28 times

Last updated: Dec 03