Skip to content

Instantly share code, notes, and snippets.

@danielsdeleo
Last active August 29, 2015 14:18
Show Gist options
  • Save danielsdeleo/4ba0124fb96968adc338 to your computer and use it in GitHub Desktop.
Save danielsdeleo/4ba0124fb96968adc338 to your computer and use it in GitHub Desktop.
Attributes Styles in Policyfiles

It just occurred to me that it's weird that roles have a totally different DSL for attributes than cookbooks, and we should take a moment to think about how attributes should work in policyfiles. In this gist are two examples, one "role style" and one "cookbook style". Let me know what you like best (but remember there's no notifications for gist comments so you have to use some other medium to make sure I see your comments).

name "cookbook-attribute-style-policy"
run_list "foo"
default_source :community
# This is the cookbook attribute DSL. You get auto-vivification:
default["abc"]["def"]["ghi"] = "xyz"
# basic attribute setting:
default["foo"] = "bar"
# you can pass in literal data structures (as long as they're one level deep)
default["baz"] = {
"more_nested_stuff" => "yup"
}
default["baz"]["an_array"] = ["a", "b", "c"]
name "role-style-policy-attrs"
run_list "foo"
default_source :community
# This is the same as the role DSL. You have to set
# everything at once (more or less). There is no auto-vivify
default_attributes "foo" => "bar",
"baz" => {
"more_nested_stuff" => "yup",
"an_array" => ["a", "b", "c"]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment