Ask Your Question
0

Hiera interpolation

asked 2016-06-28 10:16:05 -0500

gilbo gravatar image

Hi. I have a hiera hash like this:

 profiles::microservices::filesystems:
  rootvg:
    physical_volumes:
      - /dev/sda2
    logical_volumes:
      service_bin:
        size: 1G
        mountpath: /apps/lvservices
        fs_type : xfs
      service_log:
        size: 1G
        mountpath: /apps/lvservices/logs

what i want to do is lookup the values of all mountpath keys in the array and do something with them. My question is how on earth do i lookup those keys in my puppet class? (is that even possible?)

edit retag flag offensive close merge delete

Comments

What version of puppet are you using? 3.x or 4.x?. You can read the entire structure in as a hash, and then manipulate that hash to get the keys, but it'll take some fiddling to figure out how.

DarylW gravatar imageDarylW ( 2016-06-29 14:36:04 -0500 )edit

Hi. I'm on 2016.1. to be honest that's the way i've been trying but i've got absolutely nowhere, so wondered if anyone else could help! Thanks for reading.

gilbo gravatar imagegilbo ( 2016-06-30 04:09:12 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2016-07-01 09:26:44 -0500

The dig function in stdlib might help.

I use a custom function in 3.8 to grab all values for a particular key in hash of hashes:

 module Puppet::Parser::Functions
  newfunction(:collect_hash_values, :type => :rvalue) do |args|
    key = args[0]
    hash = args[1]
    array = []
    hash.each do |k,v|
      array.push(v[key])
    end 
  end
  array
end
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: 2016-06-28 10:16:05 -0500

Seen: 58 times

Last updated: Jul 01 '16