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

poise-derived (1) Versions 1.0.0

A Chef cookbook for defining lazily evaluated node attributes.

Berkshelf/Librarian
Policyfile
Knife
cookbook 'poise-derived', '~> 1.0.0'
cookbook 'poise-derived', '~> 1.0.0', :supermarket
knife cookbook site install poise-derived
knife cookbook site download poise-derived
README
Dependencies
Changelog
Quality

Poise-Derived Cookbook

Build Status Gem Version Cookbook Version Coverage Gemnasium License

A Chef cookbook for defining lazily evaluated node attributes.

Quick Start

To create a lazily evaluated node attribute:

# attributes/default.rb
default['mycookbook']['version'] = '1.0'
default['mycookbook']['url'] = lazy 'https://example.com/myapp-%{mycookbook.version}.zip'

# recipes/default.rb
node.override['mycookbook']['version'] = '2.0'

poise_archive '/srv/myapp' do
  source node['mycookbook']['url']
end

This attribute can now be used anywhere a normal string can be used and will lazily evaluate to the derived value.

Requirements

  • Chef >= 12.3

Block Attributes

When simple format strings are not enough, you can use the block form of lazy attributes:

# attributes/default.rb
default['mycookbook']['memory_percent'] = 50
default['mycookbook']['command_options'] = lazy {
  "-m #{node['memory']['total'].to_i * node['mycookbook']['memory_percent'] / 100.0}"
}

If the block returns something other than a string, it will be run through to_s.

Template Overrides

If an attribute's default value is lazy'd, any overrides to it will be treated as the string form of a lazy attribute. This allows overriding the template in a role, environment, or policy:

# attributes/default.rb
default['mycookbook']['version'] = '1.0'
default['mycookbook']['url'] = lazy 'https://example.com/myapp-%{mycookbook.version}.zip'

# recipes/default.rb
node.override['mycookbook']['url'] = 'https://myapp.com/%{mycookbook.version}.tgz'

poise_archive '/srv/myapp' do
  source node['mycookbook']['url']
end

Why Do I Need This?

Cookbook attribute files are, at heart, plain Ruby code. This has led many cookbook authors to use the naive approach to having the value of one attribute be used as part of the value of another:

# attributes/default.rb
default['mycookbook']['version'] = '1.0'
default['mycookbook']['url'] = lazy "https://example.com/myapp-#{node['mycookbook']['version']}.zip"

The problem with this is that if a wrapper cookbook wants to change the value of node['mycookbook']['version'], by the time it sets the new version the URL has already been baked so further changes to the version won't affect it. One solution here is to never use one attribute in another, but this is often ungainly. poise-derived provides a middle ground where the interpolation can be expressed cleanly and with minimal impact to the recipe code that uses it.

Sponsors

Development sponsored by Bloomberg.

The Poise test server infrastructure is sponsored by Rackspace.

License

Copyright 2016, Noah Kantrowitz

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.

Poise-Derived Changelog

v1.0.0

  • Initial release!

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

Foodcritic Metric
            

1.0.0 passed this metric

License Metric
            

1.0.0 passed this metric

No Binaries Metric
            

1.0.0 passed this metric

Publish Metric
            

1.0.0 passed this metric

Supported Platforms Metric
            

1.0.0 failed this metric

poise-derived should declare what platform(s) it supports.

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 passed this metric