Chef LWRP to dynamically set attributes.
Ruby
Pull request Compare This branch is 3 commits behind dcrosta:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
providers
resources
test/support
.gitignore
.travis.yml
README.md
metadata.rb

README.md

Description

Define an attribute dynamically using ruby blocks.

Usage

Use the preferred_attribute LWRP to define dynamic attributes to have the value of the first of an ordered list of expressions to have a non-nil value:

preferred_attribute "ipaddress" do
  maybe { node["ec2"]["public_ip"] }
  maybe { node["rackspace"]["public_ip"] }
  maybe { node["ipaddress"] }
end

Attributes are defined within the "preferred" namespace, so the above creates an attribute accessible as node["preferred"]["ipaddress"]. You can change the namespace with the namespace option to preferred_attribute; if you set it to nil, no namespacing will be applied.

The name option to preferred_attribute may be a dotted attribute path. Any parts of the attribute path which do not exist are created on demand.