Resource: replaceoradd

May 20, 2026 ยท View on GitHub

Actions

ActionDescription
editReplace lines that match the pattern. Append the line unless a source line matches the pattern.

Properties

PropertiesDescriptionTypeValues and Default
pathFile to updateStringRequired, no default
patternRegular expression to select linesRegular expression or StringRequired, no default
lineLine contentsStringRequired, no default
replace_onlyDon't append only replace matching linestrue or falseDefault is false
remove_duplicatesRemove duplicate lines matching patterntrue or falseDefault is false
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
ownerSet the owner of the fileStringno default
groupSet the group of the fileStringno default
modeSet the mode of the fileString, Integerno default
manage_symlink_sourcePass through Chef's symlink-source handling; setting it explicitly also suppresses Chef's symlink warningtrue or falseno default

Example Usage

replace_or_add "why hello" do
  path "/some/file"
  pattern "Why hello there.*"
  line "Why hello there, you beautiful person, you."
end
replace_or_add "change the love, don't add more" do
  path "/some/file"
  pattern "Why hello there.*"
  line "Why hello there, you beautiful person, you."
  replace_only true
end

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.