Provides helper methods for other cookbooks - a shared library
valOrDefault
# does return val, if val is not nil, otherwise uses default
# Very handy if you want to pick either one value, if it exist, or the node.default or similar
def valOrDefault(val, default)
Usage example. add depends "kontextwork-helpers-lib
to your metadata.rb
# if node[:key][:nested1][:nested2] is set, return that value, otherwise "other"
valOrDefault(node.dig(:key,:nested1, :nested2), "other")
valOrDefault(node.dig(:key,:nested1, :nested2), node.default.dig(:key,:nested1, :nested2))
nodeOrDefaultAttr
# does return val, if val is not nil, otherwise uses default
# Very handy if you want to pick either one value, if it exist, or the node.default or similar
def nodeOrDefaultAttr(*keys)
Usage example. add depends "kontextwork-helpers-lib
to your metadata.rb
# if node[:key][:nested1][:nested2] is set, return it, otherwise return node.default[:key][:nested1][:nested2]
# or if even that is missing, return nil
nodeOrDefaultAttr(:key,:nested1, :nested2))
The test provision via dokken
, so be sure to have a docker engine running
make prepare
make test
Right now we are testing the different sources and aspects of attribute precendence
no-attributes-test
no extra attributes in kitchen - so just attribute defaultsattributes-test
uses kitchen nodeattributes
and tests if you can overridenode.default
values with it The result is: noroles-attributes-test
uses the role attest/integration/roles/attributes_test.json
to definedefault_attributes
and the run list. The result of this is fairly suprising, the entire order is messed up