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

This commit is contained in:
Eric Renfro 2015-05-18 10:36:51 -04:00
parent a9dfd4447f
commit 80a671a8d7
2 changed files with 20 additions and 12 deletions

View file

@ -13,8 +13,9 @@ Attributes
#### sudo_rules::default #### sudo_rules::default
Key | Type | Description | Default Key | Type | Description | Default
---------------------------- | ------ | ------------------------------------ | ---------- -------------------------------- | ------ | ---------------------------------------------------------- | ----------
`['sudo_rules']['data_bag']` | String | Name of data bag to use for entries. | sudo_rules `['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 #### data bag
@ -71,12 +72,13 @@ And provide properly formatted data bag:
Contributing Contributing
------------ ------------
1. Fork the repository on Github 1. Fork the repository on Github.
2. Create a named feature branch (like `add_component_x`) 2. Switch to the develop branch.
3. Write your change 3. Create a named feature branch off develop (like `add_component_x`).
4. Write tests for your change (if applicable) 4. Write your change.
5. Run the tests, ensuring they all pass 5. Write tests for your change (if applicable).
6. Submit a Pull Request using Github 6. Run the tests, ensuring they all pass.
7. Submit a Pull Request using Github to develop branch.
or or
@ -85,5 +87,5 @@ or
License and Authors License and Authors
------------------- -------------------
Authors: Eric Renfro <erenfro@linux-help.org> Authors: Eric Renfro <erenfro@linux-help.org>
Contributers: Pieter Vogelaar

View file

@ -12,10 +12,16 @@ include_recipe "sudo"
node.override['authorization']['sudo']['include_sudoers_d'] = true node.override['authorization']['sudo']['include_sudoers_d'] = true
search_node = node['fqdn'] 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? 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.") Chef::Log.warn("This recipe uses search. Chef Solo does not support search unless you install the chef-solo-search cookbook.")
else 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 # Name
if rule["name"].kind_of?(String) if rule["name"].kind_of?(String)
rule_name = rule["name"] rule_name = rule["name"]