Kubes
2013-Apr-03 20:18 UTC
[Puppet Users] Using single hiera hash for two create_resources, and mounting filesystems
I am trying to use the same hiera hash to create the mount point and mounts. (Would be nice if mount could create the mount points using 3.1.1) My plan was to define create_mount_points and use create_resources with the same hash, and just though away what I dont use.... maybe there is a better means? Here is the mount class: class fstab::mounts ( $config = undef ) { $defaults = { atboot => true, ensure => ''mounted'', } $hiera_config = hiera_hash(''fstab::mounts'', undef) if $hiera_config { create_resources(fstab::create_mount_points, $hiera_config ) create_resources(mount, $hiera_config, $defaults) } } the define define fstab::create_mount_points ( $config = undef ) { file{ $name: ensure => directory, owner => ''root'', group => ''root'', } } and the hiera yaml fstab::mounts: ''/mnt/test'': ensure: ''mounted'' device: ''/dev/sdi'' atboot: ''true'' fstype: ''ext4'' options: ''defaults'' How do I just pass the name/title from the hash? I get Error 400 on SERVER: Invalid parameter ensure. I look like create_resources oversites all the setting for create_mount_points? Any thoughts? Or a better means? Thanks! -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
jcbollinger
2013-Apr-04 13:50 UTC
[Puppet Users] Re: Using single hiera hash for two create_resources, and mounting filesystems
On Wednesday, April 3, 2013 3:18:55 PM UTC-5, Kubes wrote:> > I am trying to use the same hiera hash to create the mount point and > mounts. (Would be nice if mount could create the mount points using 3.1.1) > > > My plan was to define create_mount_points and use create_resources with > the same hash, and just though away what I dont use.... maybe there is a > better means? > > > Here is the mount class: > > class fstab::mounts ( $config = undef ) { > $defaults = { > atboot => true, > ensure => ''mounted'', > } > $hiera_config = hiera_hash(''fstab::mounts'', undef) > if $hiera_config { > create_resources(fstab::create_mount_points, $hiera_config ) > create_resources(mount, $hiera_config, $defaults) > } > } > > the define > > define fstab::create_mount_points ( $config = undef ) { > file{ $name: > ensure => directory, > owner => ''root'', > group => ''root'', > } > } > > and the hiera yaml > > fstab::mounts: > ''/mnt/test'': > ensure: ''mounted'' > device: ''/dev/sdi'' > atboot: ''true'' > fstype: ''ext4'' > options: ''defaults'' > > > How do I just pass the name/title from the hash? I get Error 400 on > SERVER: Invalid parameter ensure. I look like create_resources oversites > all the setting for create_mount_points? > > Any thoughts? Or a better means? > > Thanks! > >I think it''s a fine idea to use one hash to drive management of both the mount and its mount point. For create_resources(), however, the keys of the inner hash must all correspond to parameters of the target resource type, so you cannot normally pass the same hash in multiple create_resources() calls. One way to approach this would be to create a defined type that models mount point + mount, giving it all the parameters it needs to cover both: define fstab::mount_and_mountpoint( $device = undef, $fstype = undef, $owner = ''root'', $group = ''root'', $mode = ''0755'', $options = ''defaults'', $atboot = true, $pass = ''0'', $dump = ''0'', $remounts = true, $ensure = ''mounted'' ) { case $ensure { ''absent'': { file { $title: ensure => ''absent'' } mount { $title: ensure => ''absent'', before => File[$title] } }, ''present'', ''unmounted'', ''mounted'': { file { $title: ensure => ''directory'', owner => $owner, group => $group, mode => $mode } mount { $title: ensure => $ensure, device => $device, fstype => $fstype, options => $options, atboot => $atboot, pass => $pass, dump => $dump, remounts => $remounts, require => File[$title] } }, default: { fail("Unexpected ensure value ''$ensure''") } } } Then use create_resources() to create instances of the defined type, instead of to create the component resources directly. Note that this also takes care of the fine point that if you ensure ''absent'' then the mount and mount point resources need to be applied in the opposite order to the one that must otherwise be used. You also get default parameter values from the defined type, which may be an advantage if you don''t like the underlying resources'' defaults. Important point: do be aware that mounts and mount points are a tricky issue because the operating system actively hides the distinction between the mount point itself and the root of the mounted filesystem. The File resource may be applied to either, depending on whether anything is mounted on the mount point when the File is applied. If you want finer control in that area then you will need to write a native custom type and provider instead of a defined type. John -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.