Seems like Augeas doesn't have a really good concept of conf file
entry AND a comment that goes with it.  I can 'ins' a comment before
the configuration item, but every time augeas runs, it will add
another.

I can re-'set' the comment before the existing configuration item, but
that won't work if the comment doesn't already exist.  Kind of a
chicken and egg.

This is what I have, and it doesn't work.  Probably the match fails on
the insert because the node doesn't exist at all -- too bad there
isn't an unless..

define sysctl::set($value, $comment=undef) {
    include sysctl
    $key = $name
    if $comment {
        $comment_use = $comment
    } else {
        $comment_use = "Managed by puppet: $key => $value"
    }

    $sysctl = '/files/etc/sysctl.conf'

    augeas { "sysctl::set $key => $value":
        changes => [ "set $sysctl/$key '$value", ],
        notify  => Service['sysctl'],
    }

    augeas { "sysctl::set insert comment for $key => $value":
        changes => [ "ins #comment before $sysctl/$key" ],
        onlyif  => "match
$sysctl/#comment[following-sibling::*[1][self::$key]] size == 0",
        require => Augeas["sysctl::set $key => $value"],
    }

    augeas { "sysctl::set change comment for $key => $value":
        changes => [ "set
$sysctl/#comment[following-sibling::*[1][self::$key]] '$comment_use'"
],
        onlyif  => "match
$sysctl/#comment[following-sibling::*[1][self::$key]] size > 0",
        require => Augeas["sysctl::set $key => $value"],
    }

}

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To post to this group, send email to puppet-users@googlegroups.com.
To unsubscribe from this group, send email to 
puppet-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en.

Reply via email to