Resource: delete_lines

May 20, 2026 ยท View on GitHub

Actions

ActionDescription
editDelete lines that match the pattern.

Properties

PropertiesDescriptionTypeValues and Default
pathFile to updateStringRequired, no default
patternRegular expression to select linesRegular expression or StringRequired, no default
ignore_missingDon't fail if the file is missingtrue or falseDefault is true
eolAlternate line end charactersStringdefault \n on unix, \r\n on windows
backupBackup before changingBoolean, Integerdefault false
manage_symlink_sourcePass through Chef's symlink-source handling; setting it explicitly also suppresses Chef's symlink warningtrue or falseno default

Example Usage

delete_lines "remove hash-comments from /some/file" do
  path "/some/file"
  pattern "^#.*"
end
delete_lines "remove hash-comments from /some/file with a regexp" do
  path "/some/file"
  pattern /^#.*/
end
delete_lines 'remove from nonexisting' do
  path '/tmp/doesnotexist'
  pattern /^#/
  ignore_missing true
end

Notes

Removes lines based on a string or regex.

If manage_symlink_source is set to true, Chef manages the symlink source file. If it is set to false, Chef disables symlink-source handling and may require the symlink to be removed before writing.