From 80a671a8d7962f2f4261900669c5aef3acb3a2d2 Mon Sep 17 00:00:00 2001 From: Eric Renfro Date: Mon, 18 May 2015 10:36:51 -0400 Subject: [PATCH] Added Pieter Vogelaar's merge request in manually. Thank you, great idea. Added attribute to do custom search queries instead of just hosts:fqdn, updated documentation --- README.md | 24 +++++++++++++----------- recipes/default.rb | 8 +++++++- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 5157836..b131c58 100644 --- a/README.md +++ b/README.md @@ -12,9 +12,10 @@ Attributes #### sudo_rules::default -Key | Type | Description | Default ----------------------------- | ------ | ------------------------------------ | ---------- -`['sudo_rules']['data_bag']` | String | Name of data bag to use for entries. | sudo_rules +Key | Type | Description | Default +-------------------------------- | ------ | ---------------------------------------------------------- | ---------- +`['sudo_rules']['data_bag']` | String | Name of data bag to use for entries. | sudo_rules +`['sudo_rules']['search_query']` | String | Custom search query for matching instead of just host:fqdn | None #### data bag @@ -71,12 +72,13 @@ And provide properly formatted data bag: Contributing ------------ -1. Fork the repository on Github -2. Create a named feature branch (like `add_component_x`) -3. Write your change -4. Write tests for your change (if applicable) -5. Run the tests, ensuring they all pass -6. Submit a Pull Request using Github +1. Fork the repository on Github. +2. Switch to the develop branch. +3. Create a named feature branch off develop (like `add_component_x`). +4. Write your change. +5. Write tests for your change (if applicable). +6. Run the tests, ensuring they all pass. +7. Submit a Pull Request using Github to develop branch. or @@ -84,6 +86,6 @@ or License and Authors ------------------- -Authors: Eric Renfro - +Authors: Eric Renfro +Contributers: Pieter Vogelaar diff --git a/recipes/default.rb b/recipes/default.rb index d68479f..15c056e 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -12,10 +12,16 @@ include_recipe "sudo" node.override['authorization']['sudo']['include_sudoers_d'] = true search_node = node['fqdn'] +if node['sudo_rules'].key?('search_query') && node['sudo_rules']['search_query'] != '' + search_query = node['sudo_rules']['search_query'] +else + search_query = "hosts:#{search_node}" +end + if Chef::Config[:solo] and nod chef_solo_search_installed? Chef::Log.warn("This recipe uses search. Chef Solo does not support search unless you install the chef-solo-search cookbook.") else - search(node['sudo_rules']['data_bag'], "hosts:#{search_node}").each do |rule| + search(node['sudo_rules']['data_bag'], search_query).each do |rule| # Name if rule["name"].kind_of?(String) rule_name = rule["name"]