Skip to content

Helps you replace text and lines in files from Chef recipes.

License

Notifications You must be signed in to change notification settings

deees/chef-patch

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

89 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Patch Cookbook

Build Status Build Status

Some handy Chef resources for when you want to append, replace or delete and lines in files.

Requirements

Platforms

  • All platforms supported by Chef

Chef

  • Chef 12.5+

Cookbooks

  • none

Resources

replace

Search the file line by line and match each line with the given regex if matched, replace the match (all occurances) with the replace parameter.

replace "/etc/sysctl.conf" do
  replace "#net.ipv4.ip_forward=1"
  with    "net.ipv4.ip_forward=1"
end

Or with a regex:

replace "/etc/sysctl.conf" do
  replace /^.*ip_forward=.*$/
  with    "net.ipv4.ip_forward=1"
end

replace_line

Search the file line by line and match each line with the given regex if matched, replace the whole line with the replace parameter.

replace_line "/etc/sysctl.conf" do
  replace "vm.swappiness"
  with    "vm.swappiness=60"
end

Or with a regex:

replace_line "/etc/sysctl.conf" do
  replace /.*vm.swappiness.*/
  with    "vm.swappiness=60"
end

append_line

Append a line to a file. It will not append the line if it is in the file already.

append_line "/etc/sysctl.conf" do
  line "vm.swappiness=60"
end

insert_line_after

Append a line to a file. It will not append the line if it is in the file already.

insert_line_after "/etc/sysctl.conf" do
  line "vm.swappiness=60"
  insert "net.ipv4.ip_forward = 1"
end

delete_line

Delete a line from a file.

delete_line "/etc/sysctl.conf" do
  line "vm.swappiness=60"
end

Or with a regex:

delete_line "/etc/sysctl.conf" do
  line /.*vm.swappiness.*/
end

Resource Propeties

All resources support a path property to specify the location of the file if you have to do multiple operations on a file:

replace_line "unique_resource_name" do
  replace  "#net.ipv4.ip_forward=1"
  with     "net.ipv4.ip_forward=1"
  path     "/etc/sysctl.conf"
end

License & Authors

The MIT License (MIT)

Copyright (c) Jens Segers

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

Helps you replace text and lines in files from Chef recipes.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 100.0%