Rich Rauenzahn
2011-Apr-06 18:14 UTC
[Puppet Users] Using puppet/augeas to manage config entry AND matching comment
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+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Rich Rauenzahn
2011-Apr-06 18:29 UTC
[Puppet Users] Re: Using puppet/augeas to manage config entry AND matching comment
On Wed, Apr 6, 2011 at 11:14 AM, Rich Rauenzahn <rrauenza@gmail.com> wrote:> 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 a better approximation -- the only bug in this now (I think) is that if the comment is cleared, but still exists, it will add another one. I could add an additional remove of the node if the size is 0, before I insert, but I''m already invoking augeas more than I want for one change. 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", "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"], } 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+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.