Adoptable Cookbooks List

Looking for a cookbook to adopt? You can now see a list of cookbooks available for adoption!
List of Adoptable Cookbooks

Supermarket Belongs to the Community

Supermarket belongs to the community. While Chef has the responsibility to keep it running and be stewards of its functionality, what it does and how it works is driven by the community. The chef/supermarket repository will continue to be where development of the Supermarket application takes place. Come be part of shaping the direction of Supermarket by opening issues and pull requests or by joining us on the Chef Mailing List.

Select Badges

Select Supported Platforms

Select Status

RSS

part_file (1) Versions 0.1.0

Provides part_file resource to change only one part of a file

Policyfile
Berkshelf
Knife
cookbook 'part_file', '~> 0.1.0', :supermarket
cookbook 'part_file', '~> 0.1.0'
knife supermarket install part_file
knife supermarket download part_file
README
Dependencies
Quality 17%

part_file cookbook

The part_file cookbook introduces the missing Chef feature - changing just
part of a file. It searches for a pattern in a file and if it founds, it
changes the line or deletes it according to the specified action.

Requirements

Chef

The cookbook is written using ChefDK 1.0.3 and tested with Chef 12.16.42.
I didn't test it with other versions of Chef and right now there are no
unit tests in the cookbook.

Cookbook Dependencies

The cookbook uses standard Chef file resource to change a file.

Usage

Place a dependency on the part_file cookbook in your cookbok's metadata.rb:

depends 'part_file', '~> 0.1.0'

Then in a recipe:

part_file '/tmp/hello.txt' do
  content 'Goodbye World'
  match 'Hello World'
end

Syntax

part_file 'name' do
  all                   TrueClass, FalseClass
  backup                FalseClass, Integer
  content               String
  group                 String, Integer
  manage_symlink_source TrueClass, FalseClass
  match                 String
  mode                  String, Integer
  owner                 String, Integer
  path                  String # defaults to 'name' if not specified
end

Actions

  • :change - Find the pattern in a string and change it to the new contents
  • :delete - Find the pattern in a string and delete it
  • :after - Find a string using the pattern and insert new contents after it
  • :before - Find a string using the pattern and insert new contents before it

Please note: actions :after and :before are not idempotent. You can use
standard Chef properties such as not_if and only_if if you want to make
a resource idempotent.

Properties

  • all - If true, perform the specified action on all matches of the pattern. Default is false, which means, that the action will be performed only on the first occurrence.
  • backup - same as property backup of file resource.
  • content - new content to be added to the file or to be changed in the file.
  • group - same as property group of file resource.
  • manage_symlink_source - same as property manage_symlink_source of file resource.
  • match - pattern to search for in the file.
  • mode - same as property mode of file resource.
  • owner - same as property owner of file resource.
  • path - the full path to the file.

Examples

Find a line starting with maintainer in file metadata.rb and change it
to maintainer 'Cookbook maintainer'

part_file 'metadata.rb' do
  content "maintainer 'Cookbook maintainer'"
  match '^maintainer .*$'
end

Find a line containing 'hello world' and delete it.

part_file '/tmp/hello.txt' do
  match 'hello world'
  action :delete
end

Find all comment lines and delete them.

part_file '/tmp/myscript.sh' do
  match '^#'
  all true
  action :delete
end

Find a line containing 'START HERE' and insert the text after it.

part_file '/tmp/test.txt' do
  match 'START HERE'
  content 'our new line 1
our new line 2
END HERE
'
  action :after
end

Find a line containing 'END HERE' and insert the text before it.

part_file '/tmp/test.txt' do
  match 'END HERE'
  content 'our new line 3
our new line 4
'
  action :before
end

Troubleshooting

Please let me know if you have any issues.

License

Author: Andrey Klyachkin (andrey.klyachkin@enfence.com)
Copyright: Copyright (c) 2017 eNFence
License: Apache License, Version 2.0

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Dependent cookbooks

This cookbook has no specified dependencies.

Contingent cookbooks

There are no cookbooks that are contingent upon this one.

Collaborator Number Metric
            

0.1.0 failed this metric

Failure: Cookbook has 0 collaborators. A cookbook must have at least 2 collaborators to pass this metric.

Contributing File Metric
            

0.1.0 failed this metric

Failure: To pass this metric, your cookbook metadata must include a source url, the source url must be in the form of https://github.com/user/repo, and your repo must contain a CONTRIBUTING.md file

Foodcritic Metric
            

0.1.0 failed this metric

FC067: Ensure at least one platform supported in metadata: part_file/metadata.rb:1
FC069: Ensure standardized license defined in metadata: part_file/metadata.rb:1
Run with Foodcritic Version 16.3.0 with tags metadata,correctness ~FC031 ~FC045 and failure tags any

No Binaries Metric
            

0.1.0 passed this metric

Testing File Metric
            

0.1.0 failed this metric

Failure: To pass this metric, your cookbook metadata must include a source url, the source url must be in the form of https://github.com/user/repo, and your repo must contain a TESTING.md file

Version Tag Metric
            

0.1.0 failed this metric

Failure: To pass this metric, your cookbook metadata must include a source url, the source url must be in the form of https://github.com/user/repo, and your repo must include a tag that matches this cookbook version number