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

dynamic-attributes (7) Versions 2.0.0

Interprets and Rewrites Node Attributes

Policyfile
Berkshelf
Knife
cookbook 'dynamic-attributes', '= 2.0.0', :supermarket
cookbook 'dynamic-attributes', '= 2.0.0'
knife supermarket install dynamic-attributes
knife supermarket download dynamic-attributes
README
Dependencies
Changelog
Quality 33%

Dynamic Attributes

Description

Interprets and rewrites node attributes defined in roles (and only roles!)
to provide more dynamicity. For instance, it can be used to get the value of
the fqdn in a role by setting an attribute to "node['fqdn']". This cookbook
will replace "node['fqdn']" by its true value at execution (in compile phase)
so it is available to other cookbooks. This allows a role to be more shareable
between nodes.

Different methods of substitution are available. Each method has its own recipe
but all are included by default recipe.

It can also generate files in a given format from content specified in
attributes, and more when combined with replace/eval feature.

Known limitation: derived attributes defined in attribute files will not read
the rewritten values. This is because attribute files are initialized before
recipes are compiled, so before the substitutions take place. This will
probably not be fixed as it is actually a feature to do the substitution during
the cookbook compilation phase, so you may use as source an attribute defined
in some other cookbook. Moreover, this limitation should not be encountered
very often and can be easily overcome by redefining the derived attributes.

Requirements

Cookbooks and gems

Declared in [metadata.rb](metadata.rb) and in [Gemfile](Gemfile).

Platforms

It should work on any platform as it is pure ruby. However it is just tested
with kitchen on a Centos 7 docker image.

Usage

To be started

Add the default recipe in you runlist in any position you want, knowing that a
source must be defined before and a reader must be after this cookbook compile
phase to see the effect in compile phase.

You may also want to tweak attributes (like whitelisting).

Read recipes documentation for more details.

Known limitations

Redefining a default attribut in cookbook attribute files from node attribute
will lead to an incorrect behavior: both original and rewritten attributes will
be read.

Ex: in something/attributes/some.rb:
ruby
default['something'] = node.default['something']

Errors / Logging

All replace/eval are run before raising any errors (which will fail the chef
run). Moreover, all successful substitutions are logged at INFO level.

Test

This cookbook is tested with kitchen on a Centos 7 docker image. A test
cookbook is used to extract attributes after default recipe has run.

For more information, see [.kitchen.yml](.kitchen.yml) and [test](test)
directory.

Attributes

Configuration is done by overriding default attributes. All configuration keys
have a default defined in [attributes/default.rb](attributes/default.rb).
Please read it to have a comprehensive view of what and how you can configure
this cookbook behavior.

Recipes

default

Include replace then eval and file recipes. So it performs all
substitutions, one after another before generating any requested file.
Attribute key (keys in hashmaps) are also modified if
needed.

Note that by default, eval has no effect as no attribute is whitelisted. In
contrary, replace is executed on all attributes.

You can look at examples defined as tests for more information.

replace

Replace (recursively) whitelisted (default: all) attributes of the form
"node['foo']['bar']" to their "true" value. It is not a string
interpolation nor a substring replacement: it will work solely if the
attributes value is exactly "node['something']".

If the target value does not exist (like "node['doesnotexist']"), it keeps
the current value (that is the string "node['doesnotexist']").

You can look at examples defined as tests for more information.

eval

Evaluate (with the use of eval method) whitelisted (default: none) attributes
as if there were referenced in a double-quote string and set the result as new
attribute value. For instance, an attribute with value "1+#{1+1}" will be
rewrited as "1+2" (as it would be in ruby).

Be careful with this substitution method as you can execute any ruby code. Be
sure to whitelist only the attributes you need.

You can look at examples defined as tests for more information.

file

Generate a file (with file resource) from attributes in a given format.

By combining it with replace/eval feature, the files can be generated from any
attributes or even from a data bag. This can be used to generate configuration
file or secrets file (with encrypted an data bag for instance).

You can look at examples defined as tests for more information.

Libraries

Provide implementation of the different methods: eval and replace.

Resources/Providers

None.

Changelog

Available in [CHANGELOG](CHANGELOG).

Contributing

Please read carefully [CONTRIBUTING.md](CONTRIBUTING.md) before making a merge
request.

License and Author

Copyright (c) 2016 Sam4Mobile, 2017-2018 Make.org

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.

Changelog

2.0.0

Main:

  • feat: make eval return real object instead of string
    • If the evalued code return a hash, the attribute will be a hash and not the string representation of the hash. Same for an int.
    • WARNING: this may break existing code relying on previous (broken) behavior. Add .to_s to evalued code if you need.
  • feat: raise an error if replaced attr is not found
    • WARNING(breaking change): raise an exception if target value does not exist
  • feat: aggregate all errors including eval ones before raising them
  • feat: output all substitutions with Chef::Log.info
  • feat: add recipe to generate a file from attrs
    • You can choose a predefined format (txt, yaml, json, ini, xml) or use the dynamic eval to generate the string you want.
  • chore: set chef version to 14 (for ruby 2.5)

Tests:

  • test: unchefize attributes before marshaling them
  • style(rubocop): disable InterpolationCheck in test
  • test: include .gitlab-ci.yml from test-cookbook
  • test: replace deprecated require_chef_omnibus

Misc:

  • doc: use karma for git format in contributing
  • doc: add a known limitation
  • style(rubocop): fix some style issues
  • chore: add 2018 to copyright notice
  • chore: set generic maintainer & helpdesk email

1.1.0

Main:

  • Handover maintenance to Make.org: update emails, copyright, urls, etc.

Tests:

  • Use Continuous Integration with gitlab-ci with latest template [20170405]

Misc:

  • Fix all rubocop offenses
  • Use cookbook_name alias in attributes

1.0.1

  • Fix non-intuitive behavior with escaped double-quote, add a test-case
  • Simplify the whitelist defined for eval tests
  • Clarify documentation on eval recipe

1.0.0

  • Initial version, supports eval and replace with configurable whitelists

Collaborator Number Metric
            

2.0.0 failed this metric

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

Contributing File Metric
            

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

2.0.0 passed this metric

No Binaries Metric
            

2.0.0 passed this metric

Testing File Metric
            

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

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