Ask Your Question
1

parsing hiera to get portion of deeply nested data structures

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

faas gravatar image

Given this hiera file:

---
lvm::volume_groups:
  vgdata4:
    physical_volumes:
      - /dev/sdc
    logical_volumes:
      varextra1:
        size: 11G
        mountpath: /var/extra1
        mountpath_require: true
        fs_type: xfs
  vgdata5:
    physical_volumes:
      - /dev/sdd
    logical_volumes:
      varextra2:
        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

Comments

What version of Puppet?

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

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

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

1 Answer

Sort by ยป oldest newest most voted
2

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

lupin gravatar image

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

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,
   $size,
   $mountpath,
   $mountpath_require,
   $fs_type,
    ){
      notify { "Creating mount-point: ${mountpath}": }
    }
 vgs{ $vgs: }
 }
edit flag offensive delete link more

Comments

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 -0500 )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

Stats

Asked: 2015-10-02 03:15:55 -0500

Seen: 141 times

Last updated: Oct 03 '15