Quite often, the need arises to do line editing instead of managing an entire file with a template resource. This cookbook supplies various resources that will help you do this.
The line resources processes the entire target file in memory. Trying to edit large files may fail.
The end of line processing was only tested using
\r\n. Using other line endings very well may not work.
The end of line string used needs to match the actual end of line used in the file
\r\nare used as the defaults but if they don't match the actual end of line used in the file the results will be weird.
Adding a line implies there is a separator on the previous line. Adding a line differs from appending characters.
Lines to be added should not contain EOL characters. The providers do not do multiline regex checks.
Missing file processing is the way it is by intention
add_to_listdo nothing, list not found so there is nothing to add to.
append_if_no_linecreate file, add the line.
delete_from_listdo nothing, the list was not found which implies there is nothing to delete
delete_linesdo nothing, the line isn't there which implies there is nothing to delete
replace_or_addcreate file, add the line
filter_linescreate file if the file changes
Chef client version 13 or greater is expected.
For more detailed information see the matching resource documentation:
append_if_no_line - Add a missing line
replace_or_add - Replace a line that matches a pattern or add a missing line
delete_lines - Delete an item from a list
add_to_list - Add an item to a list
delete_from_list - Delete lines that match a pattern
filter_lines - Supply a ruby proc or use a sample filter to edit lines. The filter_lines resource supports multiple line modfications.
- after: Insert lines after a matched line
- before: Insert lines before a matched lined
- between: Insert lines between matched lines
- comment: Change lines to comments
- delete_between: Delete the lines found between two patterns
- missing: Add missing lines to a file
- replace: Replace each instance of matched lines
- stanza: Insert or change keys in files formatted in stanzas
- substitute: Substitute text in lines matching a pattern
- Contributor: Mark Gibbons
- Contributor: Dan Webb
- Contributor: Sean OMeara
- Contributor: Antek S. Baranski