I need to replace some text in a file... there is some type, that i can pass a value and to be replace and the destination file? or anyone here have some class who does that? -- Marley Bacelar Project Fedora Ambassador VCP, VSP. VTSP., ITILF, IBM 000-076, IBM 000-330, IBM 000-331 marleybacelar@gmail.com -- 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.
You might want to check out Augeas. It might be easier to use. I''ve seen a simple define that does that, but I can''t find it. It had a grep statement in unless, and used sed to make the change. A much more complicated example can be found at http://projects.puppetlabs.com/projects/puppet/wiki/Simple_Text_Patterns On May 21, 2010, at 1:22 PM, Marley Bacelar wrote:> I need to replace some text in a file... there is some type, that i can pass a value and to be replace and the destination file? or anyone here have some class who does that? > > -- > Marley Bacelar > Project Fedora Ambassador > VCP, VSP. VTSP., ITILF, IBM 000-076, IBM 000-330, IBM 000-331 > marleybacelar@gmail.com > > > -- > 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.-- 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.
Marley Bacelar <marleybacelar@gmail.com> writes:> I need to replace some text in a file... there is some type, that i can pass > a value and to be replace and the destination file?I know this sounds like a great idea, but decades of experience with puppet and proceeding tools tell us that editing the content of files is very, very hard to get right. You would almost certainly be better off copying the right file content into place, so that you don''t have the extra complexity. As an alternative, building the file from fragments with one of the ''concatenated files'' classes is a pretty sound idea; it makes it easy have variable sections inside the file without needing to edit-in-place.> or anyone here have some class who does that?There are a couple in the common module collections; check out the wiki for the links off to ''em. Their current state may have changed since I last looked, so I don''t have a specific recommendation for you. Daniel Y''see, I learned that lesson way back when cfengine provided really good tools for doing this sort of editing, and it *always* tool much longer and was much less robust than I expected... -- ✣ Daniel Pittman ✉ daniel@rimspace.net ☎ +61 401 155 707 ♽ made with 100 percent post-consumer electrons -- 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.
On Fri, May 21, 2010 at 6:08 PM, Daniel Pittman <daniel@rimspace.net> wrote:> Marley Bacelar <marleybacelar@gmail.com> writes: > > > I need to replace some text in a file... there is some type, that i can > pass > > a value and to be replace and the destination file? > > I know this sounds like a great idea, but decades of experience with puppet > and proceeding tools tell us that editing the content of files is very, > very > hard to get right. > > You would almost certainly be better off copying the right file content > into > place, so that you don''t have the extra complexity. > > > As an alternative, building the file from fragments with one of the > ''concatenated files'' classes is a pretty sound idea; it makes it easy have > variable sections inside the file without needing to edit-in-place. > > > or anyone here have some class who does that? > > There are a couple in the common module collections; check out the wiki for > the links off to ''em. Their current state may have changed since I last > looked, so I don''t have a specific recommendation for you. > > Daniel > > Y''see, I learned that lesson way back when cfengine provided really good > tools > for doing this sort of editing, and it *always* tool much longer and was > much > less robust than I expected... > >The vast majority of our text replacement work we do is for files that have simple key/value pairs with an assignment operator. foo=bar foo: bar etc. We occasionally stray outside this with a regexp replacer, but I totally agree with Daniel here, it''s not the most robust thing in the world. Generally we do this because we want to allow people to customize extra parts of their config files, and we''ve switched daemons entirely for some services, simply based upon their ability to cope with a parts.d directory or to have "include" directives of some kind. That allows you to ship an absolute config with a default include that people are free to modify. -- 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.
> The vast majority of our text replacement work we do is for files that > have simple key/value pairs with an assignment operator. > > > foo=bar > foo: bar > > > etc. > > > We occasionally stray outside this with a regexp replacer, but I > totally agree with Daniel here, it''s not the most robust thing in the > world. > > > Generally we do this because we want to allow people to customize > extra parts of their config files, and we''ve switched daemons entirely > for some services, simply based upon their ability to cope with a > parts.d directory or to have "include" directives of some kind. > > > That allows you to ship an absolute config with a default include that > people are free to modify. >fwiw, the newest version of my concat module supports symlinking into a concat file, so if you have a config file that you would like users to drop settings it and you want them to only do so in a very specific place in a file you can now achieve that by building your config file and including a user editable file right where you want it. Very nice feature to give users some rights without loosing control of the file or its structure. It wouldn''t be too hard to extend it to make arbitrary user supplied .d directories for daemons that dont support those :) http://github.com/ripienaar/puppet-concat -- R.I.Pienaar -- 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.
Nice... I solved my probleman using the: define replace($file, $pattern, $replacement) { exec { "/usr/bin/perl -pi -e ''s/$pattern/$replacement/'' ''$file''": onlyif => "/usr/bin/perl -ne ''BEGIN { \$ret = 1; } \$ret = 0 if /$pattern/ && ! /$replacement/ ; END { exit \$ret; }'' ''$file''", } } Then i my class used: replace { "/etc/bashrc": file => "/etc/bashrc", pattern => "PS1", replacement => "PS1 DOMAINA.COM" } Worked perfectly... Know i will see the other options proposed here. Thank you evry much guys -- Marley Bacelar Project Fedora Ambassador VCP, VSP. VTSP., ITILF, IBM 000-076, IBM 000-330, IBM 000-331 marleybacelar@gmail.com 2010/5/21 R.I.Pienaar <rip@devco.net>> > The vast majority of our text replacement work we do is for files that > > have simple key/value pairs with an assignment operator. > > > > > > foo=bar > > foo: bar > > > > > > etc. > > > > > > We occasionally stray outside this with a regexp replacer, but I > > totally agree with Daniel here, it''s not the most robust thing in the > > world. > > > > > > Generally we do this because we want to allow people to customize > > extra parts of their config files, and we''ve switched daemons entirely > > for some services, simply based upon their ability to cope with a > > parts.d directory or to have "include" directives of some kind. > > > > > > That allows you to ship an absolute config with a default include that > > people are free to modify. > > > > > fwiw, the newest version of my concat module supports symlinking into a > concat file, so if you have a config file that you would like users to drop > settings it and you want them to only do so in a very specific place in a > file you can now achieve that by building your config file and including a > user editable file right where you want it. > > Very nice feature to give users some rights without loosing control of the > file or its structure. > > It wouldn''t be too hard to extend it to make arbitrary user supplied .d > directories for daemons that dont support those :) > > http://github.com/ripienaar/puppet-concat > > > -- > R.I.Pienaar > > -- > 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<puppet-users%2Bunsubscribe@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/puppet-users?hl=en. > >-- 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.