Skip to content

Instantly share code, notes, and snippets.

@jfromaniello
Created September 17, 2013 18:43
Show Gist options
  • Save jfromaniello/6598837 to your computer and use it in GitHub Desktop.
Save jfromaniello/6598837 to your computer and use it in GitHub Desktop.
tweak ulimits (in ubuntu?) with puppet
define helpers::limits (
$domain = "root",
$type = "soft",
$item = "nofile",
$value = "10000"
) {
# guid of this entry
$key = "$domain/$type/$item"
# augtool> match /files/etc/security/limits.conf/domain[.="root"][./type="hard" and ./item="nofile" and ./value="10000"]
$context = "/files/etc/security/limits.conf"
$path_list = "domain[.=\"$domain\"][./type=\"$type\" and ./item=\"$item\"]"
$path_exact = "domain[.=\"$domain\"][./type=\"$type\" and ./item=\"$item\" and ./value=\"$value\"]"
augeas { "limits_conf/$key":
context => "$context",
onlyif => "match $path_exact size != 1",
changes => [
# remove all matching to the $domain, $type, $item, for any $value
"rm $path_list",
# insert new node at the end of tree
"set domain[last()+1] $domain",
# assign values to the new node
"set domain[last()]/type $type",
"set domain[last()]/item $item",
"set domain[last()]/value $value",
],
}
}
define helpers::pamd (
$type = "session",
$control = "required",
$module,
) {
# guid of this entry
$key = "$type/$control/$module"
$context = "/files/etc/pam.d/common-session"
$path_list = "*[type=\"$type\"][module=\"$module\"]"
$path_exact = "*[type=\"$type\"][control=\"$control\"][module=\"$module\"]"
augeas { "pamd/$key":
context => "$context",
onlyif => "match $path_exact size != 1",
changes => [
"rm $path_list",
"ins 1000000 after *[last()]",
"set 1000000/type $type",
"set 1000000/control $control",
"set 1000000/module $module",
],
}
}
class usage () {
helpers::pamd {
"enable-pamd-limits": module => "pam_limits.so";
}
helpers::limits {
"myuser-soft": domain => root, type => soft, item => nofile, value => 9999;
"myuser-hard": domain => root, type => hard, item => nofile, value => 9999;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment