Skip to content

Instantly share code, notes, and snippets.

@h0tw1r3
Created February 26, 2017 02:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save h0tw1r3/7f611c7747c6e12b94a4a3b42cd7def2 to your computer and use it in GitHub Desktop.
Save h0tw1r3/7f611c7747c6e12b94a4a3b42cd7def2 to your computer and use it in GitHub Desktop.
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