title: How do I comment a line in /etc/sudoers file using Chef Recipe?
body: <p>I want to comment <code>"Defaults    requiretty"</code> line present in <code>/etc/sudoers</code> 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:</p>
  
  <pre class="lang-rb prettyprint-override"><code>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
  </code></pre>