[augeas-devel] Lens and test for sysctl.conf

Sean E. Millichamp sean at bruenor.org
Thu Sep 4 03:29:31 UTC 2008


I wanted to try using augeas+puppet to manage my sysctl.conf files.  I
couldn't find a pre-existing sysctl.conf lens so I borrowed heavily from
the shellvars lens and tweaked as necessary.  Attached are the lens and
test.  They have gotten only the most minimal review so far but seem to
do what I need.

Feedback welcome.

Sean

-------------- next part --------------
module Sysctl =
  autoload xfm

  let filter = incl "/etc/sysctl.conf"

  let eol = Util.del_str "\n"
  let key_re = /[A-Za-z0-9_.-]+/
  let eq = Util.del_str " = "
  let value = /[^\n]*/

  let comment = [ del /([#;].*)?[ \t]*\n/ "# \n" ]

  let kv = [ key key_re . eq . store value . eol ]

  let lns = (comment | kv) *

  let xfm = transform lns filter
-------------- next part --------------
(* Test for sysctl lens *)
module Test_sysctl =

  let default_sysctl = "# Kernel sysctl configuration file
# Controls IP packet forwarding
net.ipv4.ip_forward = 0

net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0

; Semicolon comments are also allowed
net.ipv4.tcp_mem = 393216 524288 786432
"

  test Sysctl.lns get default_sysctl =
    { }
    { }
    { "net.ipv4.ip_forward" = "0" }
    { }
    { "net.ipv4.conf.default.rp_filter" = "1" }
    { "net.ipv4.conf.default.accept_source_route" = "0" }
    { "kernel.sysrq" = "0" }
    { }
    { }
    { "net.ipv4.tcp_mem" = "393216 524288 786432" }

  test Sysctl.lns put default_sysctl after
    set "net.ipv4.ip_forward" "1" ;
    rm "net.ipv4.conf.default.rp_filter" ;
    rm "net.ipv4.conf.default.accept_source_route" ;
    rm "kernel.sysrq"
  = "# Kernel sysctl configuration file
# Controls IP packet forwarding
net.ipv4.ip_forward = 1


; Semicolon comments are also allowed
net.ipv4.tcp_mem = 393216 524288 786432
"

(* Local Variables: *)
(* mode: caml       *)
(* End:             *)


More information about the augeas-devel mailing list