On 2014-05-03 00:40, Matthew Burgess wrote: > On 2 May 2014 23:04, Andreas Ntaflos <d...@pseudoterminal.org > <mailto:d...@pseudoterminal.org>> wrote: > > Sound like you want to install deep-merge (packaged by Puppetlabs for > Debian as "ruby-deep-merge" and for RedHat as "rubygem-deep-merge") on > the Puppet master, set ":merge_behavior: deeper" in > /etc/puppet/hiera.yaml (and/or /etc/hiera.yaml) and restart the Puppet > master. > > Just googling a bit leads me to a really small nuance in the text in the > link you posted. The merge behaviour described on that page is for > 'hash merge lookups' and not every Hiera lookup is that. In particular, > automated class parameter binding uses hiera() not hiera_hash() so > doesn't do a hash merge lookup. If I've read the code in lvm/init.pp > correctly, that appears to be the reason for what I'm seeing.
Right, hiera() does priority lookups, and does not merge data. hiera_hash() and hiera_array() can and will merge data if ":merge_behavior" is set to "deeper" and the deep-merge Gem is installed. I think the documentation of Hiera (http://docs.puppetlabs.com/hiera/1/index.html) covers these differences and nuances nicely. > So, I guess there's 3 questions now: > > 1) Have I understood the code and documentation correctly and come to > the correct conclusion about why I'm seeing the behaviour I am? I believe so, yes. > 2) Is there a reason why the automatic class parameter binding uses > hiera() and not hiera_hash() when the parameter is a hash? This is by design (http://docs.puppetlabs.com/hiera/1/puppet.html#limitations), but I don't know much about the reasons behind it. > 3) Is there anything I can do to 'fix' this particular issue? I don't > mind carrying a local patch to puppetlabs/lvm if that's what's required, > or a config change. If not, I'll just have to resign myself to having > data duplication; the number of places we have to override the size of a > common filesystem is very low, as are the chances that the common > filesystem sizes will change in common.yaml. This is usually a case for a profile class that calls hiera_hash() and create_resources(). Here's one way to go about it (note that I don't know or use the puppetlabs-lvm module myself, and the following is untested): # /etc/puppet/environment/production/modules/profile/manifests/lvm.pp class profile::lvm { include '::lvm' $physical_volumes = hiera_hash('profile::lvm::physical_volumes', {}) create_resources('physical_volume', $physical_volumes) $volume_groups = hiera_hash('profile::lvm::volume_groups', {}) create_resources('volume_group', $volume_groups) $logical_volume = hiera_hash('profile::lvm::logical_volumes', {}) create_resources('logical_volume', $logical_volumes) } # /etc/puppet/hieradata/common.yaml --- profile::lvm::physical_volumes: '/dev/sda3': ensure: present profile::lvm::volume_groups: 'rootvg': ensure: present physical_volume: /dev/sda3 profile::lvm::logical_volumes: root_vol: size: 1G volume_group: rootvg mountpath: '/' mountpath_require: true var_vol: size: 4G volume_group: rootvg mountpath: '/var' mountpath_require: true # /etc/puppet/hieradata/web.yaml --- profile::lvm::logical_volumes: var_vol: size: 18G The above defines a profile::lvm class which you can include on nodes where you manage LVM. It uses hiera_hash() to look up hashes of data that can be fed into the puppetlabs-lvm types physical_volume, volume_group and logical_volume, and calls create_resources() on these types with that data. See http://docs.puppetlabs.com/references/latest/function.html#createresources for details on create_resources(). In common.yaml we defined that data in the form of YAML hashes under the lookup keys the profile::lvm class expects. In web.yaml we override the size parameter for the var_vol LV, so a node that includes profile::lvm and gets its data from the hierarchy level on which web.yaml resides will have an 18GB LV named "var_vol" in the VG "rootvg", mounted under /var. A more complete, practical and real-world example of roles and profiles with Hiera can be found here: <https://ask.puppetlabs.com/question/1655/an-end-to-end-roleprofile-example-using-hiera/>. It uses the same concepts as the profile::lvm class above. Andreas
signature.asc
Description: OpenPGP digital signature