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

RSS

data_file (3) Versions 0.1.1

Resources to create JSON and YAML files

Berkshelf/Librarian
Policyfile
Knife
cookbook 'data_file', '= 0.1.1'
cookbook 'data_file', '= 0.1.1', :supermarket
knife cookbook site install data_file
knife cookbook site download data_file
README
Dependencies
Changelog
Quality 50%

Data File Cookbook

Build Status Chef Supermarket GitHub Issues GitHub Tag

This is a library Chef cookbook that provides resources to create data files in JSON and YAML format.

The native file resource has the drawback of treating files like text: cookbook code has to take care of serializing data, and unless you take great care to preserve data order, it often thinks that file has changed even though the data inside it is the same (e.g. because dictionary keys are ordered differently). This clutters chef-client output and can lead to unnecessary service restarts.

The json_file and yaml_file resources exported by this cookbook accept data rather than content, and consider changes in parsed data rather than serialize text.

Recipes

  • data_file::default – empty. Can be included in the role run list to make the resources available to other cookbooks.
  • data_file::safe_yaml – install safe_yaml gem into Chef and requires it. It is strongly recommended to use this is you use YAML serialization/deserialization. Otherwise, it might be possible to prepare a malicious YAML file that would make chef-client execute arbitrary code.

Attributes

None.

Resources

Two resources are exported: json_file and yaml_file. They behave identically, only difference being the serialization format.

Actions

Inherited from file: - :create (default) - :create_if_missing - :delete

Properties

The resources have all the properties of file resource, except contents. Two new properties are defined:

  • data – data to be serialized (anything with #to_json method, including node attributes)
  • pretty (boolean, default false) – if set to true, JSON file will be pretty-printed. Meaningless for yaml_file

The content method on the resource can be used to access the serialized JSON/YAML string if anybody needs that.

Examples

include_recipe 'data_file::safe_yaml'
yaml_file '/etc/filebeat/prospectors.d/supervisord.yml' do
  data filebeat: {
         prospectors: [{
           paths: ['/var/log/supervisor/*.log'],
           document_type: 'supervisord'
         }]
       }
  owner 'root'
  group 'filebeat'
  mode '0640'
end
json_file '/path/to/config.json' do
  data node['software']['config']
  pretty true
end

Testing and Development

Rubocop, Foodcritic, Test-kitchen with kitchen-docker driver. See test/harness.sh & .kitchen.yml.

Contributing

Just send a PR on GitHub.

License

The MIT License (MIT)

Copyright (c) 2016 Maciej Pasternacki maciej@3ofcoins.net

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.

Dependent cookbooks

This cookbook has no specified dependencies.

Contingent cookbooks

There are no cookbooks that are contingent upon this one.

Change Log

Version 0.1.1 (2016-09-19)

Normalize data using resource's serialization format rather than always JSON (fixes numerical hash keys in YAML).

Version 0.1.0 (2016-03-28)

Initial release

Collaborator Number Metric
            

0.1.1 failed this metric

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

Foodcritic Metric
            

0.1.1 passed this metric