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 -- 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 rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/52849789.40401%40netzmarkt.de. For more options, visit https://groups.google.com/groups/opt_out.
You shouldn''t need a Regex for that, how about String#include? -- Posted via http://www.ruby-forum.com/. -- 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 rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/3d5fb646a817bf4a3757be6fa240d8fb%40ruby-forum.com. For more options, visit https://groups.google.com/groups/opt_out.
On Nov 14, 2013, at 3:27 AM, Rodrigo de Campos <rdcp-oP3IKE9fX2EhFhg+JK9F0w@public.gmane.org> 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 AdministratorChef’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 rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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.