Create a Logical Volume, EXT4 filesystem, mounted mount point and NFS export all via Puppet
I was building a NFS server for our users home directories to work with our FreeIPA implementation, and instead of setting up a logical volume, filesystem and mount point manually I decided to do it via Puppet. Since Puppet is our configuration management engine of choice, I might as well make something that’s reusable, right?
In our environment, we use a Puppet module called Profile, this profile module allows us to create puppet manifests for individual servers, something like this:
/etc/puppet/environments/production/modules/profile/manifests: nfs.pp fileserver.pp www.pp ns1.pp ns2.pp
This allows us to use one specific manifest for each server rather than each server having its own independent module.
For this server (nfs.pp), I’m going to use the puppetlabs-lvm puppet module, and the haraldsk/nfs puppet modules. I then create my nfs.pp manifest in my profile Puppet module manifests directory, to look like this:
Here I specify the name of the manifest, and any includes.
class profile::nfs { include nfs::server
Here I ensure that /srv/nfs is a directory that gets created or already exists on the filesystem.
file { "/srv/nfs": ensure => "directory", }
Here I specify a Physical Volume (/dev/sdb1), Volume Group (vg_data), Logical Volume (nfs), and the LV size (480G). In this module I can also specify the mount point (/srv/nfs) and make it required (true).
class { 'lvm': volume_groups => { 'vg_data' => { physical_volumes => [ '/dev/sdb1' ], logical_volumes => { 'nfs' => { 'size' => '480G', 'mountpath' => '/srv/nfs', 'mountpath_require' => true, }, }, }, }, }
Here I create the entry in /etc/exports for /srv/nfs with the appropriate options that I wanted.
nfs::export { '/srv/nfs': clients => '*', options => ['rw', 'insecure', 'sync', 'all_squash', 'no_wdelay', ] } }
Here is the full nfs.pp Puppet manifest:
class profile::nfs { include nfs::server file { "/srv/nfs": ensure => "directory", } class { 'lvm': volume_groups => { 'vg_data' => { physical_volumes => [ '/dev/sdb1' ], logical_volumes => { 'nfs' => { 'size' => '480G', 'mountpath' => '/srv/nfs', 'mountpath_require' => true, }, }, }, }, } nfs::export { '/srv/nfs': clients => '*', options => ['rw', 'insecure', 'sync', 'all_squash', 'no_wdelay', ] } }