Ask Your Question

hiera_hash - undefine lower-priority value

asked 2015-09-14 16:53:23 -0600

JohnsonEarls gravatar image

Is there any way, when using hiera_hash(), to "undefine" a hash key that was defined in a lower-priority hierarchy?

For example, given this Hiera hierarchy:

:merge_behavior: "deeper"
  - "yaml"
  - "overrides"
  - "testing"
  - "global"
  :datadir: "."

with these data sources:


  bar: 4


  baz: ???


  bar: 1
  baz: 2
  quux: 3

In testing.yaml, what can I use to replace the ??? so that baz does not appear in the resulting hash? The desired result would be:

$ hiera --hash --config hiera.yaml foo
{ "bar"=>4, "quux"=>3 }

As far as I can tell, any value I put into baz in testing.yaml results in that value becoming part of the hash (or results in an error if yaml interprets the value as a different data type).

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2015-09-15 03:40:15 -0600

updated 2015-09-17 02:29:57 -0600


The only way to remove completely an entry in a lower hierarchy is using advanced options of the deepmerge gem. The documentation is there :

Basically, you'll have to use something like this (found in the hiera doc)

:merge_behavior: deeper
  :knockout_prefix => '--'

and give the value of the knockout_prefix you chose to the entry you want to remove using the following form :

source = {:x => ['--1', '2']}
dest   = {:x => ['1', '3']}
Results: {:x => ['2','3']}

Here the "--1" entry is used to remove the "1" entry during the merge, using only "--" will just clear the entry.

Hope this will help you.

edit flag offensive delete link more


First, this needs to be entered in `hiera.yaml` as `:knockout_prefix: '--'` - but unfortunately, this behaviour is not quite what I want. It's used to remove items from a hash element. When given for the hash element value itself, it replaces the value with a blank, it doesn't remove the element.

JohnsonEarls gravatar imageJohnsonEarls ( 2015-09-16 18:36:29 -0600 )edit

You're not using the correct form, to remove the entry you have to provide "--%{value}" as a value not "--". This is in the deep_merge gem documentation : source = {:x => ['--1', '2']} dest = {:x => ['1', '3']} dest.ko_deep_merge!(source) Results: {:x => ['2','3']} I updated the answer

ThinkBriK gravatar imageThinkBriK ( 2015-09-17 02:25:56 -0600 )edit

Thanks, but this is still not what I want. Please see the original question - I don't want to remove a value that is embedded in a hash element, I want to *remove the hash element entirely*.

JohnsonEarls gravatar imageJohnsonEarls ( 2015-10-02 20:38:20 -0600 )edit

I have exactly the same issue. For instance, in our production environments we have conlegacapi: false defined in sysinf.yaml They shouldn't exist at all for test environments which inherit from sysinf.yaml and do overrides in testenvsysinf.yaml.

todd.ellner gravatar imagetodd.ellner ( 2015-11-02 12:58:16 -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

1 follower


Asked: 2015-09-14 16:53:23 -0600

Seen: 699 times

Last updated: Sep 17 '15