I have a file containing: line1 line2 line3 How can I use puppet (template/file) to maintain line1 and line3 and ignore line2? Thanks! -- 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.
Hi, That depends on what you have available to you to test for. You can use ''if'' statements and other ruby conditional statements in your template which can test values of variables and make appropriate decisions. You might like to provide a bit more info on what you are trying to do? Den On 15/03/2012, at 3:10, Gamon <bruno.pessanha@gmail.com> wrote:> I have a file containing: > > line1 > line2 > line3 > > How can I use puppet (template/file) to maintain line1 and line3 and > ignore line2? > > Thanks! > > -- > 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.
Hi Den, I''d like to have a template that would contain: line1 <%= value1 %> line2 <%= value2 %> line3 <%= value3 %> But the template should ignore line2 for example if that already exists. Something like greping for line2 and if that exists, keep the original line. Bruno On Mar 14, 9:13 pm, Denmat <tu2bg...@gmail.com> wrote:> Hi, > > That depends on what you have available to you to test for. > > You can use ''if'' statements and other ruby conditional statements in your template which can test values of variables and make appropriate decisions. > > You might like to provide a bit more info on what you are trying to do? > > Den > > On 15/03/2012, at 3:10, Gamon <bruno.pessa...@gmail.com> wrote: > > > > > > > > > I have a file containing: > > > line1 > > line2 > > line3 > > > How can I use puppet (template/file) to maintain line1 and line3 and > > ignore line2? > > > Thanks! > > > -- > > 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 athttp://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.
Hello Gamon, Am 15.03.2012 13:24, schrieb Gamon:> I''d like to have a template that would contain: > > line1 <%= value1 %> > line2 <%= value2 %> > line3 <%= value3 %> > > But the template should ignore line2 for example if that already > exists. Something like greping for line2 and if that exists, keep the > original line.i think you should take a look a augeas: http://projects.puppetlabs.com/projects/1/wiki/puppet_augeas Regards, Dennis
Hi Dennis, I think that implementing augeas is a bit unfeasible for us at this moment. Would you know how to do that using ruby instead? Thanks! Bruno On Mar 15, 2:00 pm, Dennis Hoppe <dennis.ho...@debian-solutions.de> wrote:> Hello Gamon, > > Am 15.03.2012 13:24, schrieb Gamon: > > > I''d like to have a template that would contain: > > > line1 <%= value1 %> > > line2 <%= value2 %> > > line3 <%= value3 %> > > > But the template should ignore line2 for example if that already > > exists. Something like greping for line2 and if that exists, keep the > > original line. > > i think you should take a look a augeas: > > http://projects.puppetlabs.com/projects/1/wiki/puppet_augeas > > Regards, Dennis > > signature.asc > < 1KViewDownload-- 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.
Hi Bruno, We need to be clear what you want. Are you trying to make changes ''on the fly'' to an existing file or are you trying to produce a file and contents from puppet? Using templates overwrites the content of existing files, as does using source =>. So what you can do is the following. class s { $var1 = ''a'' $var2 = ''b'' $var3 = ''c'' $t = inline_template('' <% unless var2 %> <%= var1 %> <%= var3 %> <% else %> <%= var1 %> <%= var2 %> <%= var3 %> <% end %> '') notify {$t:} } If you want to make changes to an existing common configuration file then Augeas is probably the best option - unless you want to create your own ''lens''. Puppet is all about enforcing state - so you know what the contents of your file will be on your nodes, that content can different per node, but Puppet doesn''t handle unknown content - stuff it can''t know. You might be wanting to manage a file at first creation and after that you don''t care about the content but that is unclear and not implied in your question. Sorry, that said I should also point out that you can use facter to grep for values in a file and then use that resultant fact in your template or Puppet decision making. Also apologies for any errors above in advance (on a bus so not checking syntax - so use the puppet docs for further info). Den On 16/03/2012, at 0:27, Gamon <bruno.pessanha@gmail.com> wrote:> Hi Dennis, > > I think that implementing augeas is a bit unfeasible for us at this > moment. Would you know how to do that using ruby instead? > > Thanks! > > Bruno > > On Mar 15, 2:00 pm, Dennis Hoppe <dennis.ho...@debian-solutions.de> > wrote: >> Hello Gamon, >> >> Am 15.03.2012 13:24, schrieb Gamon: >> >>> I''d like to have a template that would contain: >> >>> line1 <%= value1 %> >>> line2 <%= value2 %> >>> line3 <%= value3 %> >> >>> But the template should ignore line2 for example if that already >>> exists. Something like greping for line2 and if that exists, keep the >>> original line. >> >> i think you should take a look a augeas: >> >> http://projects.puppetlabs.com/projects/1/wiki/puppet_augeas >> >> Regards, Dennis >> >> signature.asc >> < 1KViewDownload > > -- > 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.
On Mar 15, 7:24 am, Gamon <bruno.pessa...@gmail.com> wrote:> I''d like to have a template that would contain: > > line1 <%= value1 %> > line2 <%= value2 %> > line3 <%= value3 %> > > But the template should ignore line2 for example if that already > exists. Something like greping for line2 and if that exists, keep the > original line.What you request is not possible, though a similar effect can probably be achieved. Puppet templates are processed on the master to produce a single file, then that whole file is transported to wherever the manifest says it should go. There is no way to after the fact adapt it to whatever file may be in the target location already. On the other hand, you can determine in advance what is in the target file and communicate it to Puppet via a custom fact. Then your template can use the fact value to create whatever the output is that you want. Overall, however, what you are asking runs against Puppet''s grain. Why shouldn''t Puppet know in advance whether line2 should be present, and if so, what it should contain? It is usually better to tell Puppet how a node should be configured than to try to make it adapt to how the node is already configured. If you''re talking about managing a file that is also dynamically modified by some other agent then you are asking for trouble. This whole discussion has been rather abstract, however. If you can be more specific about what you want to do then we may be able to offer better advice and / or alternatives. John -- 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.
See the following: https://github.com/puppetlabs/puppetlabs-stdlib/tree/master/lib/puppet/provider/file_line On Mar 16, 6:02 am, jcbollinger <John.Bollin...@stJude.org> wrote:> On Mar 15, 7:24 am, Gamon <bruno.pessa...@gmail.com> wrote: > > > I''d like to have a template that would contain: > > > line1 <%= value1 %> > > line2 <%= value2 %> > > line3 <%= value3 %> > > > But the template should ignore line2 for example if that already > > exists. Something like greping for line2 and if that exists, keep the > > original line. > > What you request is not possible, though a similar effect can probably > be achieved. Puppet templates are processed on the master to produce > a single file, then that whole file is transported to wherever the > manifest says it should go. There is no way to after the fact adapt > it to whatever file may be in the target location already. > > On the other hand, you can determine in advance what is in the target > file and communicate it to Puppet via a custom fact. Then your > template can use the fact value to create whatever the output is that > you want. > > Overall, however, what you are asking runs against Puppet''s grain. > Why shouldn''t Puppet know in advance whether line2 should be present, > and if so, what it should contain? It is usually better to tell > Puppet how a node should be configured than to try to make it adapt to > how the node is already configured. If you''re talking about managing > a file that is also dynamically modified by some other agent then you > are asking for trouble. > > This whole discussion has been rather abstract, however. If you can > be more specific about what you want to do then we may be able to > offer better advice and / or alternatives. > > John-- 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.
Thanks for all your answers and suggestions. So, what happens is that I want to push a file from the master to a client. But the problem is that after starting the service that reads that file, it appends one line to it, which is an authorization token. Like this: #1 file is pushed from the master to the client: line1 line2 #2 the service starts on the client for the first time and it appends the new line (line3): line1 line2 line3 #3 if I restart puppet the file will be changed to: line1 line2 #4 the service stops working because the line 3 (authorization token) is gone. I''d really like to manage all lines in that file but the one that is added after the service is started. I hope is clear now. Bruno On Mar 16, 2:02 pm, jcbollinger <John.Bollin...@stJude.org> wrote:> On Mar 15, 7:24 am, Gamon <bruno.pessa...@gmail.com> wrote: > > > I''d like to have a template that would contain: > > > line1 <%= value1 %> > > line2 <%= value2 %> > > line3 <%= value3 %> > > > But the template should ignore line2 for example if that already > > exists. Something like greping for line2 and if that exists, keep the > > original line. > > What you request is not possible, though a similar effect can probably > be achieved. Puppet templates are processed on the master to produce > a single file, then that whole file is transported to wherever the > manifest says it should go. There is no way to after the fact adapt > it to whatever file may be in the target location already. > > On the other hand, you can determine in advance what is in the target > file and communicate it to Puppet via a custom fact. Then your > template can use the fact value to create whatever the output is that > you want. > > Overall, however, what you are asking runs against Puppet''s grain. > Why shouldn''t Puppet know in advance whether line2 should be present, > and if so, what it should contain? It is usually better to tell > Puppet how a node should be configured than to try to make it adapt to > how the node is already configured. If you''re talking about managing > a file that is also dynamically modified by some other agent then you > are asking for trouble. > > This whole discussion has been rather abstract, however. If you can > be more specific about what you want to do then we may be able to > offer better advice and / or alternatives. > > John-- 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 Mar 19, 10:11 am, Gamon <bruno.pessa...@gmail.com> wrote:> Thanks for all your answers and suggestions. > > So, what happens is that I want to push a file from the master to a > client. But the problem is that after starting the service that reads > that file, it appends one line to it, which is an authorization token.It''s pretty nasty for a service to routinely modify its own configuration files. Is there any way you can make it not do that? For instance, is there an option to make it put the authorization token in a separate file? Alternatively, perhaps the file you''re trying to manage isn''t well- characterized as a configuration file. In that case, perhaps you''re trying to manage the wrong resource, and there might be a bona fide configuration file that would be a better target for your efforts. Or, similarly, perhaps you can *make* a separate file. For example, some config files can have an ''include'' or similar directive that directs the program to read additional configuration from a separate file. In that case you could put all the lines you want to manage in that separate file, and in the main file ensure only that an appropriate ''include'' is present. If none of those options are available, then perhaps you can switch to better software. (Though more likely not.) If the only avenue to your desired end is to accept the software''s modifications to your managed file, then it is possible to achieve that. For a one-line addition that you can distinguish from the other lines of the file, I would suggest this approach: 1) Create a custom fact that that captures the authorization token line of the target file, if it''s present. Distribute it via pluginsync. 2) Use the custom fact value to interpolate the authorization token line into your template for the file 3) Ensure that Puppet relationships are in place to prevent Puppet from starting the service before managing the file. I emphasize that that is a distinctly worse solution than any of the others I suggested. Aside from being messy, it contains a race condition: if the service is started or the authorization token is otherwise changed in the middle of a Puppet run (except by Puppet), then Puppet could still lose the token. John -- 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.