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.pessa...@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+unsubscr...@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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en.

Reply via email to