Skip to content

Instantly share code, notes, and snippets.

@ticean
Created November 17, 2011 04:51
Show Gist options
  • Save ticean/1372387 to your computer and use it in GitHub Desktop.
Save ticean/1372387 to your computer and use it in GitHub Desktop.
Chef MungeOneLine
# @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