cookbook 'attrbagger', '~> 0.2.1'
attrbagger (2) Versions 0.2.1 Follow0
Gets attributes from data bags.
cookbook 'attrbagger', '~> 0.2.1', :supermarket
knife supermarket install attrbagger
knife supermarket download attrbagger
attrbagger
Cookbook
Get attributes from data bags.
Somewhat fancy.
Requirements
Attrbagger does not depend on any other cookbooks. It works with both
chef-solo
and chef-client
by using data_bag_item
.
Attributes
attrbagger::default
<table>
<tr>
<th>Key</th><th>Type</th><th>Description</th><th>Default</th>
</tr>
<tr>
<td><tt>node['attrbagger']['autoload']</tt></td>
<td><tt>Boolean</tt></td>
<td>
Used when including the default recipe to decide whether or
not to autoload attributes.
</td>
<td><tt>true</tt></td>
</tr>
<tr>
<td><tt>node['attrbagger']['precedence_level']</tt></td>
<td><tt>Boolean</tt></td>
<td>
The default precedence level to use when not specified in each
<tt>Hash</tt> of <tt>node['attrbagger']['configs']</tt>.
</td>
<td><tt>:override</tt></td>
</tr>
<tr>
<td><tt>node['attrbagger']['configs']</tt></td>
<td><tt>Hash</tt></td>
<td>
The <tt>Hash</tt> structure requires unique string keys representing the
targets of each merged "data bag cascade" in a <tt>::</tt>-separated
format to denote nesting, e.g. <tt>first::second</tt>. The value of
each key must be a <tt>Hash</tt> with an optional <tt>precedence_level</tt>
key (default <tt>override</tt>) and a required <tt>bag_cascade</tt> key.
The value of the <tt>bag_cascade</tt> key must be an <tt>Array</tt> containing
strings representing the cascade of attributes that will be
loaded. The only type of resource currently supported is
<tt>data_bag_item</tt>, e.g.
<tt>'bag_cascade' => ['data_bag_item[a::b]', 'data_bag_item[c::d]']</tt>.
</td>
<td><tt>{}</tt></td>
</tr>
</table>
Usage
Attrbagger may be used either as a library or by including the
recipe[attrbagger::default]
in one's run_list
.
When used as a library, the Attrbagger
class may be used via its
.autoload!
class method, or by creating a new instance and using the
#load_config
instance method. Both require injection of the
run_context
, which is available in any recipe as self.run_context
.
See the Attrbagger tests for more usage examples.
Inclusion of recipe[attrbagger::default]
in the run_list
will result
in the node['attrbagger']['configs']
hash being walked and merged into
the node's attribute precedence level specified via each hash's
precedence_level
attribute (defaulting to
node['attrbagger']['precedence_level']
.
An example role using attrbagger to load application-specific
configuration from a base, custom, and dynamic environment-specific data
bag, as well as loading mail service configuration might look like this:
name 'attrbagger_example' description 'Attrbagger example role' default_attributes( 'deployment_env' => 'demo', 'attrbagger' => { 'configs' => { 'example_app' => { 'precedence_level' => 'override', 'bag_cascade' => [ 'data_bag_item[applications::base::example_app]', 'data_bag_item[applications::example_app]', "data_bag_item[applications::config_<%= node['deployment_env'] %>::example_app]" ] }, 'services::mail' => { 'precedence_level' => 'default', 'bag_cascade' => [ 'data_bag_item[services::mail]' ] } } }, 'example_app' => { 'awesome' => true }, 'mail' => { 'host' => 'localhost', 'port' => 25 } ) run_list( 'recipe[attrbagger]', # ... other stuff )
This would result in the following actions:
- Load
data_bag_item('applications', 'base')
and merge itsexample_app
hash withnode.default['example_app']
, then assign the result tonode.override['example_app']
- Load
data_bag_item('applications', 'example_app')
and merge the entire data bag contents (except for builtin attributes likeid
andchef_type
) withnode.default['example_app']
, then assign the result tonode.override['example_app']
. - Load
data_bag_item('applications', 'config_demo')
and merge itsexample_app
hash withnode.default['example_app']
, then assign the result tonode.override['example_app']
- Load
data_bag_item('services', 'mail')
and merge the entire data bag contents (except for builtin attributes likeid
andchef_type
) withnode.default['services']['mail']
, then assign the result tonode.default['services']['mail']
.
Contributing
License
Authors
Dependent cookbooks
This cookbook has no specified dependencies.
Contingent cookbooks
There are no cookbooks that are contingent upon this one.
Collaborator Number Metric
0.2.1 failed this metric
Failure: Cookbook has 1 collaborators. A cookbook must have at least 2 collaborators to pass this metric.
Contributing File Metric
0.2.1 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.2.1 failed this metric
FC064: Ensure issues_url is set in metadata: attrbagger/metadata.rb:1
FC065: Ensure source_url is set in metadata: attrbagger/metadata.rb:1
FC066: Ensure chef_version is set in metadata: attrbagger/metadata.rb:1
FC067: Ensure at least one platform supported in metadata: attrbagger/metadata.rb:1
Run with Foodcritic Version 16.3.0 with tags metadata,correctness ~FC031 ~FC045 and failure tags any
No Binaries Metric
0.2.1 passed this metric
Testing File Metric
0.2.1 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.2.1 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.2.1 failed this metric
0.2.1 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.2.1 failed this metric
FC064: Ensure issues_url is set in metadata: attrbagger/metadata.rb:1
FC065: Ensure source_url is set in metadata: attrbagger/metadata.rb:1
FC066: Ensure chef_version is set in metadata: attrbagger/metadata.rb:1
FC067: Ensure at least one platform supported in metadata: attrbagger/metadata.rb:1
Run with Foodcritic Version 16.3.0 with tags metadata,correctness ~FC031 ~FC045 and failure tags any
No Binaries Metric
0.2.1 passed this metric
Testing File Metric
0.2.1 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.2.1 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.2.1 failed this metric
FC065: Ensure source_url is set in metadata: attrbagger/metadata.rb:1
FC066: Ensure chef_version is set in metadata: attrbagger/metadata.rb:1
FC067: Ensure at least one platform supported in metadata: attrbagger/metadata.rb:1
Run with Foodcritic Version 16.3.0 with tags metadata,correctness ~FC031 ~FC045 and failure tags any
0.2.1 passed this metric
Testing File Metric
0.2.1 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.2.1 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.2.1 failed this metric
0.2.1 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