Skip to content
Browse files

Add user_array_node_attr attr and rename data_bag to data_bag_name.

  • Loading branch information...
1 parent 4616a26 commit 22ead77bb6939c0138f05d8e650382d107b7105a @fnichol committed Aug 14, 2012
Showing with 26 additions and 12 deletions.
  1. +10 −1 README.md
  2. +2 −1 attributes/default.rb
  3. +14 −10 recipes/data_bag.rb
View
11 README.md
@@ -142,12 +142,21 @@ Use this recipe when you want data bag driven data in your workflow.
## <a name="attributes"></a> Attributes
-### <a name="attributes-data-bag"></a> data_bag
+### <a name="attributes-data-bag-name"></a> data_bag_name
The data bag name containing a group of user account information. This is used
by the `data_bag` recipe to use as a database of user accounts. The default is
`"users"`.
+### <a name="attributes-user-array-node-attr"></a> user_array_node_attr
+
+The node attributes containing an array of users to be managed. If a nested
+hash in the node's attributes is required, then use a `/` between subhashes.
+For example, if the users' array is stored in `node['system']['accounts']`),
+then set `node['homesick']['user_array_node_attr']` to `"system/accounts"`.
+
+The default is `"users"`.
+
## <a name="lwrps"></a> Resources and Providers
### <a name="lwrps-castle"></a> homesick_castle
View
3 attributes/default.rb
@@ -19,4 +19,5 @@
# limitations under the License.
#
-default['homesick']['data_bag'] = "users"
+default['homesick']['data_bag_name'] = "users"
+default['homesick']['user_array_node_attr'] = "users"
View
24 recipes/data_bag.rb
@@ -17,18 +17,22 @@
# limitations under the License.
#
-bag = node['homesick']['data_bag']
-users = begin
- data_bag(bag)
-rescue => ex
- Chef::Log.info("Data bag #{bag.join('/')} not found (#{ex}), so skipping")
- []
-end
-
include_recipe 'homesick'
-Array(node['users']).each do |i|
- u = data_bag_item(bag, i)
+bag = node['homesick']['data_bag_name']
+
+# Fetch the user array from the node's attribute hash. If a subhash is
+# desired (ex. node['base']['user_accounts']), then set:
+#
+# node['homesick']['user_array_node_attr'] = "base/user_accounts"
+user_array = node
+node['homesick']['user_array_node_attr'].split("/").each do |hash_key|
+ user_array = user_array.send(:[], hash_key)
+end
+
+# only manage the subset of users defined
+Array(user_array).each do |i|
+ u = data_bag_item(bag, i.gsub(/[.]/, '-'))
Array(u['homesick_castles']).each do |castle|
homesick_castle castle['name'] do

0 comments on commit 22ead77

Please sign in to comment.
Something went wrong with that request. Please try again.