On Sunday, December 9, 2012 at 8:14 PM, Juanje Ojeda Croissier wrote:
As I had a similar problem time ago, i did create a similar cookbook
(which is also at the community site and be installed from there):
There are some examples about how to use this LWRP. Maybe one of them
fit your needs.
I have one action that append a line just after specific line, but not
to prepend, but I could add this action easily if is needed.
It’s something to be used just if is really no way to use a template,
it tries to be as much idempotence as it can.
On Mon, Dec 10, 2012 at 2:06 AM, charles Keagle <firstname.lastname@example.org (mailto:email@example.com)> wrote:
Doesn’t append add the new line to the end of the file? I need to add it
before a line I define.
Maybe something like:
prepend_if_no_line “+:mongod:cron crond” do
string "-: ALL : ALL"
Still looking at inserting a line before another line when necessary.
On 12/9/2012 12:55 AM, Sean OMeara wrote:
This comes up ALL THE TIME, so…
I whipped up a line cookbook on the community site that’ll help you out.
add depends ‘line’ in a cookbook’s metadata.rb, then in a recipe you can
append_if_no_line “hello world” do
string "HI THERE I AM STRING"
It’s alpha code cut at 4am, so let me know how it works =)
On Sun, Dec 9, 2012 at 1:37 AM, <firstname.lastname@example.org (mailto:email@example.com)> wrote:
I am new to Chef and Ruby and trying to figure out the proper way to add
to /etc/security/access.conf prior to the last line that denies
Not sure yet whether the best way is to use a Chef command of a Ruby
I do not see a way in Chef to insert a new line searched for if the line
not already exist in the file prior to another line in the file.
I thought this would work:
file.replace_line_if_no_match but that adds it after the last line in the
In security, all the entries in access.conf that allow access have to
to the line that denies everything not already allowed.
Basically, I want to see if “+:mongod:cron crond\n” already exists. If
does, do not do anything. However, if it does not exist, insert it prior
: ALL : ALL\n”.
What is the best way in a Chef Recipe to do this?
Just a quick friendly warning:
Only you can evaluate the tradeoffs of this approach vs. templating the whole file, but you should be aware of the risk. Namely, when you manage individual lines of a file like this, you create a situation where the exact file content isn’t specified by a single resource, but rather by the history of the node’s run_list and cookbook versions over time.
For example, you may edit a file to stick a certain line in some place. Later, you need to change the line you inserted, so you change the recipe so it edits that line. Now when you bring up a new host, it doesn’t add the line, so your new boxes are different than older ones. I’m sure you can imagine more variations on this type of issue.
That said, I’ve heard of use cases where other alternatives are so onerous that people find the risk acceptable. You should take a moment to make certain this is the situation you’re in before proceeding with this approach.