Skip to content

Instantly share code, notes, and snippets.

@h0tw1r3
Created Feb 26, 2017
Embed
What would you like to do?
Hacky way to apply mount options to fstab entries
class profile::fstab {
define fstab::mount($options) {
$mount = $title
exec { "fstab_remount_${mount}":
command => "/bin/env mount -o remount ${title}",
refreshonly => true
}
$mo = prefix($options, "$mount:")
fstab::mount::helper { $mo: }
}
define fstab::mount::helper {
$mo = split($title, ':')
$mount = $mo[0]
$option = $mo[1]
$opt = split($option, '=')
$base_changes = [
'ins opt after opt[last()]',
"set opt[last()] '${opt[0]}'",
]
if size($opt) > 1 {
$changes = concat($base_changes, [
"set opt[last()]/value '${opt[1]}'"
])
} else {
$changes = $base_changes
}
augeas { "set_${mount}_${option}":
context => "/files/etc/fstab/*[file='${mount}']",
incl => '/etc/fstab',
lens => 'fstab.lns',
changes => $changes,
onlyif => "match /files/etc/fstab/*[file='${mount}'][count(opt[.='${opt[0]}']) = 0] size > 0",
notify => Exec["fstab_remount_${mount}"],
}
}
fstab::mount { ['/', '/home', '/usr', '/var', '/var/log', '/var/log/audit', '/srv/nmrepo']:
options => ['noatime','nodiratime','barrier=0','errors=remount-ro']
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment