entry.pp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # From: https://projects.puppetlabs.com/projects/puppet/wiki/Puppet_Augeas
  2. # Changes:
  3. # - modified match to use 'size == 0' rather than 'size != 1'
  4. # - avoid nested define
  5. #
  6. # Example:
  7. # limits::entry { 'wso2esb':
  8. # domain => "@mygroup",
  9. # type => 'soft',
  10. # item => 'nofile',
  11. # value => '4096'
  12. # }
  13. define limits::entry (
  14. $domain,
  15. $type,
  16. $item,
  17. $value
  18. ) {
  19. case $item {
  20. 'core': {}
  21. 'data': {}
  22. 'fsize': {}
  23. 'memlock': {}
  24. 'nofile': {}
  25. 'rss': {}
  26. 'stack': {}
  27. 'cpu': {}
  28. 'nproc': {}
  29. 'as': {}
  30. 'maxlogins': {}
  31. 'maxsyslogins': {}
  32. 'priority': {}
  33. 'locks': {}
  34. 'sigpending': {}
  35. 'msqqueue': {}
  36. 'nice': {}
  37. 'rtprio': {}
  38. default: {
  39. warning("Unknown item '$item' so you may get augeas errors - see the limits.conf man page for valid values")
  40. }
  41. }
  42. # guid of this entry
  43. $key = "${domain}/${type}/${item}"
  44. # augtool> match /files/etc/security/limits.conf/domain[.="root"][./type="hard" and ./item="nofile" and ./value="10000"]
  45. $context = '/files/etc/security/limits.conf'
  46. $path_list = "domain[.=\"${domain}\"][./type=\"${type}\" and ./item=\"${item}\"]"
  47. $path_exact = "domain[.=\"${domain}\"][./type=\"${type}\" and ./item=\"${item}\" and ./value=\"${value}\"]"
  48. augeas { "limits_conf/${key}":
  49. context => $context,
  50. onlyif => "match ${path_exact} size == 0",
  51. changes => [
  52. # remove all matching to the ${domain}, ${type}, ${item}, for any ${value}
  53. "rm ${path_list}",
  54. # insert new node at the end of tree
  55. "set domain[last()+1] ${domain}",
  56. # assign values to the new node
  57. "set domain[last()]/type ${type}",
  58. "set domain[last()]/item ${item}",
  59. "set domain[last()]/value ${value}",
  60. ],
  61. }
  62. }