Anyone know the best way (most efficient) to handle text entries in files without using Templates? Ensuring multiple entries exist in a file from a cookbook (array) attribute. If they are overwritten, they would be re-added.
I know how to do this with perl and bash, but it would be a little more resource intensive than I would like.
The configuration file in question is changing a few times a week under control of a process that I cannot modify, but I still need to ensure that certain information is in the resultant configuration file.
Thanks to everyone who has been helping this newbie along…
Randy
Does this config file allow you to do includes? If you can separate
the chef values into a separate file and include that, you'll be able
to use a template and that's a lot easier/cleaner.
Jake.
On Thu, Jan 26, 2012 at 3:01 PM, Van Fossan,Randy vanfossr@oclc.org wrote:
Anyone know the best way (most efficient) to handle text entries in files
without using Templates? Ensuring multiple entries exist in a file from a
cookbook (array) attribute. If they are overwritten, they would be
re-added.
I know how to do this with perl and bash, but it would be a little more
resource intensive than I would like.
The configuration file in question is changing a few times a week under
control of a process that I cannot modify, but I still need to ensure that
certain information is in the resultant configuration file.
Thanks to everyone who has been helping this newbie along..
Randy
I'll look into using include(s). I am not sure if I can though.
-----Original Message-----
From: Jake Vanderdray [mailto:jvanderdray@customink.com]
Sent: Friday, January 27, 2012 9:58 AM
To: chef@lists.opscode.com
Subject: [chef] Re: Most efficient way to handle text in config files (without a template)
Does this config file allow you to do includes? If you can separate the chef values into a separate file and include that, you'll be able to use a template and that's a lot easier/cleaner.
Jake.
On Thu, Jan 26, 2012 at 3:01 PM, Van Fossan,Randy vanfossr@oclc.org wrote:
Anyone know the best way (most efficient) to handle text entries in
files without using Templates? Ensuring multiple entries exist in a
file from a cookbook (array) attribute. If they are overwritten,
they would be re-added.
I know how to do this with perl and bash, but it would be a little
more resource intensive than I would like.
The configuration file in question is changing a few times a week
under control of a process that I cannot modify, but I still need to
ensure that certain information is in the resultant configuration file.
Thanks to everyone who has been helping this newbie along..
Randy
Hello Van,
here is an example of handling config files by chef without template you
might be interested in.
http://goo.gl/qe2Wn
Thank you,
Max
On Fri, Jan 27, 2012 at 10:15 AM, Van Fossan,Randy vanfossr@oclc.orgwrote:
I'll look into using include(s). I am not sure if I can though.
-----Original Message-----
From: Jake Vanderdray [mailto:jvanderdray@customink.com]
Sent: Friday, January 27, 2012 9:58 AM
To: chef@lists.opscode.com
Subject: [chef] Re: Most efficient way to handle text in config files
(without a template)
Does this config file allow you to do includes? If you can separate the
chef values into a separate file and include that, you'll be able to use a
template and that's a lot easier/cleaner.
Jake.
On Thu, Jan 26, 2012 at 3:01 PM, Van Fossan,Randy vanfossr@oclc.org
wrote:
Anyone know the best way (most efficient) to handle text entries in
files without using Templates? Ensuring multiple entries exist in a
file from a cookbook (array) attribute. If they are overwritten,
they would be re-added.
I know how to do this with perl and bash, but it would be a little
more resource intensive than I would like.
The configuration file in question is changing a few times a week
under control of a process that I cannot modify, but I still need to
ensure that certain information is in the resultant configuration file.
Thanks to everyone who has been helping this newbie along..
Randy
The way I handled it doesn't at all meet your requirement... i did use
a template.
It isn't the cleanest, and I wish I could switch to the Util::FileEdit
method, as that is much cleaner... but it doesn't seem to serve the
same purpose.
This checks if my line text exists, and if it does not it adds it at a
specific point that I specify. If you didn't care where in the file it
went, you could skip the insertpoint piece, and just append to
'output'
Here's the template:
<% output = File.read(@oldfile) -%>
<% @insertlines.each do |line| -%>
<% unless (output.match(/^#{line['text']}$/i)) then -%>
<% output =
output.sub(/^(#{line['insertpoint']})$/,"\1\n#{line['text']}") -%>
<% end -%>
<% end -%>
<%= output -%>
-Jesse
On Fri, Jan 27, 2012 at 13:24, Max Gorbul max@gorbul.net wrote:
Hello Van,
here is an example of handling config files by chef without template you
might be interested in.
http://goo.gl/qe2Wn
Thank you,
Max
On Fri, Jan 27, 2012 at 10:15 AM, Van Fossan,Randy vanfossr@oclc.org
wrote:
I'll look into using include(s). I am not sure if I can though.
-----Original Message-----
From: Jake Vanderdray [mailto:jvanderdray@customink.com]
Sent: Friday, January 27, 2012 9:58 AM
To: chef@lists.opscode.com
Subject: [chef] Re: Most efficient way to handle text in config files
(without a template)
Does this config file allow you to do includes? If you can separate the
chef values into a separate file and include that, you'll be able to use a
template and that's a lot easier/cleaner.
Jake.
On Thu, Jan 26, 2012 at 3:01 PM, Van Fossan,Randy vanfossr@oclc.org
wrote:
Anyone know the best way (most efficient) to handle text entries in
files without using Templates? Ensuring multiple entries exist in a
file from a cookbook (array) attribute. If they are overwritten,
they would be re-added.
I know how to do this with perl and bash, but it would be a little
more resource intensive than I would like.
The configuration file in question is changing a few times a week
under control of a process that I cannot modify, but I still need to
ensure that certain information is in the resultant configuration file.
Thanks to everyone who has been helping this newbie along..
Randy
Forgot to mention:
@oldfile is the file being updated by the template
@insertlines is an array (or hash) of hashes
each insertline will have ['text'], which is the text to insert, and
['insertpoint'] which is what line to search for and insert the
['text'] after.
On Sat, Jan 28, 2012 at 10:00, Jesse Campbell hikeit@gmail.com wrote:
The way I handled it doesn't at all meet your requirement... i did use
a template.
It isn't the cleanest, and I wish I could switch to the Util::FileEdit
method, as that is much cleaner... but it doesn't seem to serve the
same purpose.
This checks if my line text exists, and if it does not it adds it at a
specific point that I specify. If you didn't care where in the file it
went, you could skip the insertpoint piece, and just append to
'output'
Here's the template:
<% output = File.read(@oldfile) -%>
<% @insertlines.each do |line| -%>
<% unless (output.match(/^#{line['text']}$/i)) then -%>
<% output =
output.sub(/^(#{line['insertpoint']})$/,"\1\n#{line['text']}") -%>
<% end -%>
<% end -%>
<%= output -%>
-Jesse
On Fri, Jan 27, 2012 at 13:24, Max Gorbul max@gorbul.net wrote:
Hello Van,
here is an example of handling config files by chef without template you
might be interested in.
http://goo.gl/qe2Wn
Thank you,
Max
On Fri, Jan 27, 2012 at 10:15 AM, Van Fossan,Randy vanfossr@oclc.org
wrote:
I'll look into using include(s). I am not sure if I can though.
-----Original Message-----
From: Jake Vanderdray [mailto:jvanderdray@customink.com]
Sent: Friday, January 27, 2012 9:58 AM
To: chef@lists.opscode.com
Subject: [chef] Re: Most efficient way to handle text in config files
(without a template)
Does this config file allow you to do includes? If you can separate the
chef values into a separate file and include that, you'll be able to use a
template and that's a lot easier/cleaner.
Jake.
On Thu, Jan 26, 2012 at 3:01 PM, Van Fossan,Randy vanfossr@oclc.org
wrote:
Anyone know the best way (most efficient) to handle text entries in
files without using Templates? Ensuring multiple entries exist in a
file from a cookbook (array) attribute. If they are overwritten,
they would be re-added.
I know how to do this with perl and bash, but it would be a little
more resource intensive than I would like.
The configuration file in question is changing a few times a week
under control of a process that I cannot modify, but I still need to
ensure that certain information is in the resultant configuration file.
Thanks to everyone who has been helping this newbie along..
Randy
Hi
Time ago I needed something similar and I did a LWRP to manage plain
files using Util::FileEdit. I've just uploaded some improvements and
some examples to the README:
And I've also uploaded to the comunity site, in case anyone like to
use from there:
http://community.opscode.com/cookbooks/conf
By the way the Util::FileEdit doesn't implement some methods I needed,
so I added to the cookbook into the 'libraries' directory. But it's
also pending to be merged: http://tickets.opscode.com/browse/CHEF-2740
I hope this help. And any feedback or suggestion about the LWRP would
be very appreciated.
Thanks
On Sat, Jan 28, 2012 at 3:33 PM, Jesse Campbell hikeit@gmail.com wrote:
Forgot to mention:
@oldfile is the file being updated by the template
@insertlines is an array (or hash) of hashes
each insertline will have ['text'], which is the text to insert, and
['insertpoint'] which is what line to search for and insert the
['text'] after.
On Sat, Jan 28, 2012 at 10:00, Jesse Campbell hikeit@gmail.com wrote:
The way I handled it doesn't at all meet your requirement... i did use
a template.
It isn't the cleanest, and I wish I could switch to the Util::FileEdit
method, as that is much cleaner... but it doesn't seem to serve the
same purpose.
This checks if my line text exists, and if it does not it adds it at a
specific point that I specify. If you didn't care where in the file it
went, you could skip the insertpoint piece, and just append to
'output'
Here's the template:
<% output = File.read(@oldfile) -%>
<% @insertlines.each do |line| -%>
<% unless (output.match(/^#{line['text']}$/i)) then -%>
<% output =
output.sub(/^(#{line['insertpoint']})$/,"\1\n#{line['text']}") -%>
<% end -%>
<% end -%>
<%= output -%>
-Jesse
On Fri, Jan 27, 2012 at 13:24, Max Gorbul max@gorbul.net wrote:
Hello Van,
here is an example of handling config files by chef without template you
might be interested in.
http://goo.gl/qe2Wn
Thank you,
Max
On Fri, Jan 27, 2012 at 10:15 AM, Van Fossan,Randy vanfossr@oclc.org
wrote:
I'll look into using include(s). I am not sure if I can though.
-----Original Message-----
From: Jake Vanderdray [mailto:jvanderdray@customink.com]
Sent: Friday, January 27, 2012 9:58 AM
To: chef@lists.opscode.com
Subject: [chef] Re: Most efficient way to handle text in config files
(without a template)
Does this config file allow you to do includes? If you can separate the
chef values into a separate file and include that, you'll be able to use a
template and that's a lot easier/cleaner.
Jake.
On Thu, Jan 26, 2012 at 3:01 PM, Van Fossan,Randy vanfossr@oclc.org
wrote:
Anyone know the best way (most efficient) to handle text entries in
files without using Templates? Ensuring multiple entries exist in a
file from a cookbook (array) attribute. If they are overwritten,
they would be re-added.
I know how to do this with perl and bash, but it would be a little
more resource intensive than I would like.
The configuration file in question is changing a few times a week
under control of a process that I cannot modify, but I still need to
ensure that certain information is in the resultant configuration file.
Thanks to everyone who has been helping this newbie along..
Randy
--
Juanje