Bryan Ross
2009-Sep-10 15:42 UTC
[Puppet Users] Adding comments to config files with augeas
Hi, I''ve got a ''define'' that I use to set kernel parameters in /etc/sysctl.conf using the augeas type. It works well, but I''d like to be able to add a comment line directly above my the parameter to explain what it does and why it''s been changed. We currently just add a comment in site.pp, but that''s not much use to local admins. Unfortunately, I can''t seem to find any way of inserting arbitrary strings using augeas. I tried the ''insert'' command, but after some reading I understand now that ins/insert is only meant for controlling where a parameter should be put in the file. Here''s a simplified version of a (broken) sysctl define. I know why this doesn''t work - it''s just to give an idea of what I''d like to get working! define sysctl::config ($value, $comment) { augeas { "sysctl_$name": context => "/files/etc/sysctl.conf", changes => [ "set $name $value", "insert ''# ${comment}'' before $name", ], onlyif => "get $name != $value", } } Anyone have any ideas? TIA, Bryan --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
David Lutterkort
2009-Sep-10 21:07 UTC
[Puppet Users] Re: Adding comments to config files with augeas
On Thu, 2009-09-10 at 16:42 +0100, Bryan Ross wrote:> Unfortunately, I can''t seem to find any way of inserting arbitrary > strings using augeas. I tried the ''insert'' command, but after some > reading I understand now that ins/insert is only meant for controlling > where a parameter should be put in the file.Comments for most files[1] show up as nodes with label ''#comment'' and a value that contains the comment without the leading ''#[ \t]*''. Therefore, to add a comment, you need to first create a ''#comment'' node and then set it to whatever you want the comment to be.> Here''s a simplified version of a (broken) sysctl define. I know why > this doesn''t work - it''s just to give an idea of what I''d like to get > working! > > define sysctl::config ($value, $comment) { > augeas { "sysctl_$name": > context => "/files/etc/sysctl.conf", > changes => [ > "set $name $value", > "insert ''# ${comment}'' before $name", > ], > onlyif => "get $name != $value", > } > }Almost ;) What you want for changes is changes => [ "set $name $value", "insert #comment before $name", "set #comment[last()] ''Look Ma, a comment''" ] David [1] There are some inconsistencies that we are gradually fixing; the lens for sysctl.conf gets it right. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Bryan Ross
2009-Sep-11 09:06 UTC
[Puppet Users] Re: Adding comments to config files with augeas
2009/9/10 David Lutterkort <lutter@redhat.com>:> Comments for most files[1] show up as nodes with label ''#comment'' and a > value that contains the comment without the leading ''#[ \t]*''. > Therefore, to add a comment, you need to first create a ''#comment'' node > and then set it to whatever you want the comment to be.Many thanks David - works perfectly! I can also understand where my thinking was wrong. For anyone googling this, here''s a working example: node default { sysctl::config { "fs.file-max": value => 65536, comment => "Maximum number of filehandles", } } class sysctl { define config ($value, $comment) { file { "/etc/sysctl.conf": mode => 644, owner => root, group => root, ensure => present, } augeas { "sysctl_$name": context => "/files/etc/sysctl.conf", changes => [ "set $name $value", "insert #comment before $name", "set #comment[last()] ''$comment''" ], onlyif => "get $name != $value", notify => Exec["/sbin/sysctl -p"], } exec { "/sbin/sysctl -p": subscribe => File["/etc/sysctl.conf"], refreshonly => true, } } } Cheers, Bryan --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---