Created
November 17, 2011 04:51
-
-
Save ticean/1372387 to your computer and use it in GitHub Desktop.
Chef MungeOneLine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# @see https://github.com/infochimps/cluster_chef/blob/version_3/site-cookbooks/hadoop_cluster/libraries/munge_one_line.rb | |
module MungeOneLine | |
# | |
# @param [String] name - name for the resource invocation | |
# @param [String] filename - the file to modify (in-place) | |
# @param [String] old_line - the string to replace | |
# @param [String] new_line - the string to insert in its place | |
# @param [String] shibboleth - a simple foolproof string that should be | |
# present after this works | |
# | |
def munge_one_line(name, filename, old_line, new_line, shibboleth) | |
execute name do | |
command %Q{sed -i -e 's|#{old_line}|#{new_line}| ' '#{filename}'} | |
not_if %Q{grep -q -e '#{shibboleth}' '#{filename}'} | |
only_if{ File.exists?(filename) } | |
yield if block_given? | |
end | |
end | |
end | |
class Chef::Recipe | |
include MungeOneLine | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment