This cookbook is maintained by the Sous Chefs. The Sous Chefs are a community of Chef cookbook maintainers working together to maintain important cookbooks. If you’d like to know more please visit sous-chefs.org (opens in a new tab) or come chat with us on the Chef Community Slack in #sous-chefs (opens in a new tab).
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 (opens in a new tab) - Add a missing line
- replace_or_add (opens in a new tab) - Replace a line that matches a pattern or add a missing line
- delete_lines (opens in a new tab) - Delete lines that match a pattern
- add_to_list (opens in a new tab) - Add an item to a list
- delete_from_list (opens in a new tab) - Delete an item from a list
- filter_lines (opens in a new tab) - 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
- replace_between: Replace lines between 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
This project exists thanks to all the people who contribute. (opens in a new tab)
Thank you to all our backers!
Support this project by becoming a sponsor. Your logo will show up here with a link to your website.