Ask Your Question

parsing hiera to get portion of deeply nested data structures

asked 2015-10-02 03:15:55 -0600

faas gravatar image

Given this hiera file:

      - /dev/sdc
        size: 11G
        mountpath: /var/extra1
        mountpath_require: true
        fs_type: xfs
      - /dev/sdd
        size: 21G
        mountpath: /var/extra2
        mountpath_require: true
        fs_type: ext4

I would like to extract the mountpath in my puppet plan. I've tried some variants i've found with examples, but with no result. I like a list of mountpaths to loop through and create directories if needed. I have to confess that this part of puppet is new to me: create_resources and complex data structures...

edit retag flag offensive close merge delete


What version of Puppet?

GregLarkin gravatar imageGregLarkin ( 2015-10-02 10:22:50 -0600 )edit

puppet-master: 3.7.5(.1.el6) puppet (client): 3.8.1(.1.el6)

faas gravatar imagefaas ( 2015-10-02 17:21:59 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2015-10-03 03:09:52 -0600

lupin gravatar image

updated 2015-10-03 12:43:49 -0600

Your version of Puppet doesn't have the iteration feature enabled by default thus, you need to create a multiple define type to extract the value of the parameter that you wanted. Having said that, the LVM module can create the mount-point and do the mounting for you if you remove the 'mountpath_require' option though it might take a few couple of extra Puppet runs.

If you're going to pursue the creation of directories as you initially intended here's the code that works on your provided data input( this won't work if you define multiple LV in a VG - customise accordingly).

class hashtest {

 $list_vgs = hiera('lvm::volume_groups')
 $vgs = keys($list_vgs)

 define vgs ($vg = $title, ){
    $list_vgs = hiera('lvm::volume_groups')
    $lvs = $list_vgs[$vg]['logical_volumes']
    create_resources(lvs, $lvs)
 define lvs (
   $lv = $title,
      notify { "Creating mount-point: ${mountpath}": }
 vgs{ $vgs: }
edit flag offensive delete link more


Thank you very much! I've got the code running without doubling configuration data. Nice to see such an automatic looping code construct.

faas gravatar imagefaas ( 2015-10-05 08:23:04 -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-10-02 03:15:55 -0600

Seen: 184 times

Last updated: Oct 03 '15