In case there is any doubt, you can go nuts with Chef::Util::FileEdit. If one is using search_file_replace, internally it is simply:
new_contents << ((method == 1) ? replace : line.gsub!(exp, replace))
Meaning if need be, I can do something silly:
ruby_block 'fix remi.repo' do action :nothing block do f = Chef::Util::FileEdit.new('/etc/yum.repos.d/remi.repo') f.search_file_replace(/\$releasever/, '%i' % major) f.search_file_replace(/(\[remi\].*?)enabled=0(.*?\[)/m, '\1enabled=1\2') f.write_file end end
Lovely! The above is needed as I only want to enable [remi], but not [remi-test] which resides in the same file. (Of course I could just ship my own .repo file, too. Choices, choices.)