I want to delete the line configuration (This word "configuration" is inside the angular brackets in the file "hdfs-site.xml"). I tried using this code but no luck.
ruby_block "delete_lines_in_hdfs_site" do
block do
file = Chef::Util::FileEdit.new("/opt/hadoop-2.4.1/etc/hadoop/hdfs-site.xml")
file.search_file_delete_line(/<configuration>/)
end
end
You need to end the ruby block with
file.write_file
Otherwise the changes are not written out.
While I agree that using a template is preferred and considered best practices, there are times you need to edit an existing file which may have variations and not fit the template model.
You do not add to or remove lines from files with chef. Instead you replace the configuration file with yours, which you put into your cookbook under files/ or templates/ forlder.
template "/opt/hadoop-2.4.1/etc/hadoop/hdfs-site.xml"
or
cookbook_file "/opt/hadoop-2.4.1/etc/hadoop/hdfs-site.xml"
When you just add/replace lines in config files, you cannot be sure, that after upgrade of installed software your config files are right.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With