cookbook 'data_file', '~> 0.1.2'
data_file (3) Versions 0.1.2 Follow1
Resources to create JSON and YAML files
cookbook 'data_file', '~> 0.1.2', :supermarket
knife supermarket install data_file
knife supermarket download data_file
Data File Cookbook
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 andrequire
s 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 makechef-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, defaultfalse
) – if set totrue
, JSON file will be pretty-printed. Meaningless foryaml_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.2 (2016-10-06)
Fix a dumb bug in json_file
that was causing infinite recursion.
Fix kitchen test.
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.2 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.2 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.2 failed this metric
FC066: Ensure chef_version is set in metadata: data_file/metadata.rb:1
FC067: Ensure at least one platform supported in metadata: data_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.2 passed this metric
Testing File Metric
0.1.2 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.2 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
0.1.2 failed this metric
0.1.2 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.2 failed this metric
FC066: Ensure chef_version is set in metadata: data_file/metadata.rb:1
FC067: Ensure at least one platform supported in metadata: data_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.2 passed this metric
Testing File Metric
0.1.2 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.2 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
0.1.2 failed this metric
FC067: Ensure at least one platform supported in metadata: data_file/metadata.rb:1
Run with Foodcritic Version 16.3.0 with tags metadata,correctness ~FC031 ~FC045 and failure tags any
0.1.2 passed this metric
Testing File Metric
0.1.2 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.2 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
0.1.2 failed this metric
0.1.2 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