On Nov 14, 2013, at 3:27 AM, Rodrigo de Campos <[email protected]> wrote:
> Hi all,
>
> I'm trying to run the code below. Basically I want to include the users
> "user" and "user2" after the line "Authentication:". I'm running this
> ruby_block inside a Chef recipe and in a first moment it works as expected,
> however, after I run "chef-solo" again the recipe is applied again and two
> more lines are created in the destination file. I need a way for my script to
> check for the existence of "user" and "user2" lines and then stop the script
> and write nothing.
>
> I suspect I should use some kind of regular expression but I am not sure how.
>
> Any ideas? Below follows the code.
>
> Thanks for your help.
>
>
> ruby_block "insert_line_to_sshd" do
> block do
> file = Chef::Util::FileEdit.new("/tmp/testconf")
> file.insert_line_after_match("Authentication:", "AllowUsers/1 user")
> file.insert_line_after_match("Authentication:", "AllowUsers/1 user2")
> file.write_file
> end
> end
>
> --
> Rodrigo de Campos
> Unix System Administrator
Chef’s FileEdit is useful, but does lack some functionality. What you could do
is call search_file_delete_line for the two lines you’re adding. Hacky, but it
should work every time.
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/rubyonrails-talk/CBF4AFEB-94E1-4DAB-8229-222A2FEAA0E9%40gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.