Skip to content

Instantly share code, notes, and snippets.

@juanje
Created November 15, 2011 22:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juanje/1368640 to your computer and use it in GitHub Desktop.
Save juanje/1368640 to your computer and use it in GitHub Desktop.
Add include? and replace(str, str2) to Chef::Resource::File
class Chef
class Resource
class File
def include?(str)
return false unless ::File.exists?(@path)
file_content = IO.read @path
if file_content =~ /#{str}/
Chef::Log.info("file[#{@path}] contains the string '#{str}'")
true
else
Chef::Log.info("file[#{@path}] doesn't contains the string '#{str}'")
false
end
end
def replace(str, str2)
Chef::Log.info("replacing '#{str}' with '#{str2}' at #{@path}")
old_content = IO.read @path
content old_content.gsub(str, str2)
end
end
end
end
file "/home/#{node.user}/.gtk-bookmarks" do
replace("smb", "nfs") if include? "smb"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment