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

The materialize cookbook has been deprecated

Author provided reason for deprecation:

The materialize cookbook has been deprecated and is no longer being maintained by its authors. Use of the materialize cookbook is no longer recommended.

RSS

materialize (1) Versions 1.0.0

Implements a materialized view pattern for searches

Policyfile
Berkshelf
Knife
cookbook 'materialize', '~> 1.0.0', :supermarket
cookbook 'materialize', '~> 1.0.0'
knife supermarket install materialize
knife supermarket download materialize
README
Dependencies
Changelog
Quality 17%

materialize

Build Status

This cookbook provides a way to materialize a data-structure into a Chef databag, and then easily retrieve it on another node. This can be useful if, for example, you want to amortize the cost of a large search one time, rather than repeat it on a thousand nodes.

Requirements

Platforms

  • Any platform supported by Chef

Chef

  • Chef 12.1+

Cookbooks

  • none

Usage

  1. Make this cookbook a dependency of the cookbook that will use either the read or write functions.
  2. Call the functions.
  3. There is no step three.

Write

Lets say you have a cookbook with a big search, to build something like ssh_known_hosts. In a typical Chef cookbook, you might write the following:

data = []
search(:node, 'fqdn:* AND ipaddress:* AND keys_ssh_host_rsa_public:* AND host_dsa_public:*') do |n|
  data << "#{n['fqdn']},#{n['ipaddress']} #{n['keys']['ssh']['host_rsa_public']}"
  data << "#{n['fqdn']},#{n['ipaddress']} #{n['keys']['ssh']['host_dsa_public']}"
end
data = data.sort

To build up your data for the ssh_known_hosts file. This woudl result in a global search across every node in your infrastructure on every convergence, which, as you get larger, will be pretty brutal.

With this cookbook, you would do the following instead:

materialize('ssh_known_hosts') do
  data = []
  search(:node, 'fqdn:* AND ipaddress:* AND keys_ssh_host_rsa_public:* AND host_dsa_public:*') do |n|
    data << "#{n['fqdn']},#{n['ipaddress']} #{n['keys']['ssh']['host_rsa_public']}"
    data << "#{n['fqdn']},#{n['ipaddress']} #{n['keys']['ssh']['host_dsa_public']}"
  end
  data.sort
end

This would take the output of your search query and store it in a data bag called 'materialize', with the key of 'ssh_known_hosts'. You want to make sure this happens on one node only, rather than on every node. (For example, move it to another recipe, or have a node attribute, or check on node name - whatever. Just don't run it every time.)

Read

To get your value back out, you would do something like this:

begin
  ssh_known_hosts_content = retrieve('ssh_known_hosts').join("\n")
rescue
  # Protect against empty cache
  ssh_known_hosts_content = IO.read('/etc/ssh/ssh_known_hosts')
end

file "/etc/ssh/ssh_known_hosts" do
  owner "root"
  mode "0644"
  content ssh_known_hosts_content
end

Development

This cookbook comes with unit tests!

$ bundle install
$ bundle exec rspec

And with functional tests!

$ kitchen test default

License & Authors

Author: Cookbook Engineering Team (cookbooks@chef.io)

Copyright: 2011-2016, Chef Software, Inc.

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.

materialize Cookbook CHANGELOG

This file is used to list changes made in each version of the materialize cookbook.

v1.0.0 (2016-09-16)

  • Require Chef 12.1
  • Add unit / linting testing in Travis CI
  • Improve kitchen config
  • Add contributing and testing docs
  • Remove Guardfile
  • Add maintainers docs
  • Add Rakefile for testing
  • Add source_url, issues_url, and chef_version to metadata

Collaborator Number Metric
            

1.0.0 failed this metric

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

Contributing File Metric
            

1.0.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

Cookstyle Metric
            

1.0.0 failed this metric

Chef/Deprecations/FoodcriticFile: Do not include the `.foodcritic` config file for the deprecated Foodcritic cookbook linter. (https://docs.chef.io/workstation/cookstyle/chef_deprecations_foodcriticfile): materialize/.foodcritic: 1
Chef/Modernize/DatabagHelpers: Use the `data_bag_item` helper instead of `Chef::DataBagItem.load` or `Chef::EncryptedDataBagItem.load`. (https://docs.chef.io/workstation/cookstyle/chef_modernize_databaghelpers): materialize/libraries/materialize.rb: 39

Run with Cookstyle Version 7.32.1 with cops Chef/Deprecations,Chef/Correctness,Chef/Sharing,Chef/RedundantCode,Chef/Modernize,Chef/Security,InSpec/Deprecations

No Binaries Metric
            

1.0.0 passed this metric

Testing File Metric
            

1.0.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
            

1.0.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