diff options
author | James Shubin <james@shubin.ca> | 2014-03-09 21:23:53 -0400 |
---|---|---|
committer | James Shubin <james@shubin.ca> | 2014-03-16 22:39:07 -0400 |
commit | 70b41db233f28fcb39011b0bd694ba5211ef4989 (patch) | |
tree | a1ed9dab4396dfcd5739a912e64f4523538202a4 /lib | |
parent | 7057c914942eb0fdfd061ad227a5c5ac255d296d (diff) | |
download | puppet-gluster-70b41db233f28fcb39011b0bd694ba5211ef4989.tar.gz puppet-gluster-70b41db233f28fcb39011b0bd694ba5211ef4989.tar.xz puppet-gluster-70b41db233f28fcb39011b0bd694ba5211ef4989.zip |
Add advanced set group support for anyone without stock support.
This adds custom set group support for users that might not have the
feature (I think it might only exist in RHS) and also to users who want
to add their own custom groups! Please ping me if the stock groups gain
or lose parameters, or if their set values change!
Diffstat (limited to 'lib')
-rw-r--r-- | lib/facter/gluster_property.rb | 68 |
1 files changed, 51 insertions, 17 deletions
diff --git a/lib/facter/gluster_property.rb b/lib/facter/gluster_property.rb index 4c47dd4..17a889d 100644 --- a/lib/facter/gluster_property.rb +++ b/lib/facter/gluster_property.rb @@ -17,29 +17,55 @@ require 'facter' -groupdir = '/var/lib/glusterd/groups/' +groupdir = '/var/lib/glusterd/groups/' # dir from the upstream package + +# find the module_vardir +dir = Facter.value('puppet_vardirtmp') # nil if missing +if dir.nil? # let puppet decide if present! + dir = Facter.value('puppet_vardir') + if dir.nil? + var = nil + else + var = dir.gsub(/\/$/, '')+'/'+'tmp/' # ensure trailing slash + end +else + var = dir.gsub(/\/$/, '')+'/' +end + +if var.nil? + # if we can't get a valid vardirtmp, then we can't continue + valid_setgroupdir = nil +else + module_vardir = var+'gluster/' + valid_setgroupdir = module_vardir.gsub(/\/$/, '')+'/groups/' +end found = {} -if File.directory?(groupdir) - Dir.glob(groupdir+'*.*').each do |f| - b = File.basename(f) +# loop through each directory to avoid code duplication... later dirs override! +[valid_setgroupdir, groupdir].each do |g| - if not found.key?(b) - found[b] = {} # initialize - end + if not(g.nil?) and File.directory?(g) + Dir.glob(g+'*.*').each do |f| + b = File.basename(f) - groups = File.open(f, 'r').read # read into str - groups.each_line do |line| - split = line.split('=') # split key=value pairs - if split.length == 2 - key = split[0] - value = split[1] - if found[b].key?(key) - # NOTE: error found in file... - print "There is a duplicate key in the '#{b}' group." + # a later entry overrides an earlier one... + #if not found.key?(b) + found[b] = {} # initialize (or erase) + #end + + groups = File.open(f, 'r').read # read into str + groups.each_line do |line| + split = line.split('=') # split key=value pairs + if split.length == 2 + key = split[0] + value = split[1] + if found[b].key?(key) + # NOTE: error found in file... + print "There is a duplicate key in the '#{b}' group." + end + found[b][key] = value end - found[b][key] = value end end end @@ -66,4 +92,12 @@ found.keys.each do |x| end end +# has the custom group directory been created yet? +Facter.add('gluster_property_groups_ready') do + #confine :operatingsystem => %w{CentOS, RedHat, Fedora} + setcode { + (File.directory?(valid_setgroupdir) ? 'true':'false') + } +end + # vim: ts=8 |