I want to comment "Defaults requiretty"
line present in /etc/sudoers
file using Chef. If it is already commented, the ruby code should skip commenting it. I'm using CentOS 6.7 operating system. So far I have done this in my recipe:
files = Dir.glob("/home/cent/etc/*")
files.each do |file_name|
text = File.read(sudoers)
replace = text.gsub!(/Defaults requiretty/, "#Defaults requiretty")
File.open(sudoers, "w") { |file| file.puts replace }
end