Avi Miller wrote:
> Hey Bryan,
> 
> Bryan Kearney wrote:
>>    augeas { "sshd_conf_group_sshuser":
>>        context =>  "/files/etc/ssh/sshd_config",
>>        changes =>  "set AllowGroups/10000 sshuser",
>>        onlyif =>  "match AllowGroups != sshuser
>>    }
> 

The current type does not support what you want. Tehre are 2 issues. 
One, match currently only returns the nodes.. not the values. Second, I 
gave you no "not include".

The supplied patch file solves both problems. It adds a matchValues 
command that will scan the values, and not the nodes. So.. if you apply 
this to a 0.24.x version you should be able to run this:

    augeas { "sshd_conf_group_sshuser":
         context =>  "/files/etc/ssh/sshd_config",
         changes =>  "set AllowGroups/1000 sshuser",
         onlyif  =>  "matchValue AllowGroups/* !include sshuser",
     }


I want to check with James about how best he would prefer me to merge 
this in, but then I will mainline it.

-- bk


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To post to this group, send email to puppet-users@googlegroups.com
To unsubscribe from this group, send email to 
puppet-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en
-~----------~----~----~----~------~----~------~--~---

diff --git a/lib/puppet/provider/augeas/augeas.rb b/lib/puppet/provider/augeas/augeas.rb
index 0ffddeb..588bfa5 100644
--- a/lib/puppet/provider/augeas/augeas.rb
+++ b/lib/puppet/provider/augeas/augeas.rb
@@ -99,6 +99,7 @@ Puppet::Type.type(:augeas).provide(:augeas) do
     # Used by the need_to_run? method to process match filters. Returns
     # true if there is a match, false if otherwise
     def process_match(cmd_array)
+
         return_value = false
 
         #validate and tear apart the command
@@ -109,30 +110,64 @@ Puppet::Type.type(:augeas).provide(:augeas) do
 
         #Get the values from augeas
         aug = open_augeas()
-        result = aug.match(path) || ''
+        result = aug.match(path) || []
         # Now do the work
-        if (!result.nil?)
-            case verb
-                when "size":
-                    fail("Invalid command: #{cmd_array.join(" ")}") if cmd_array.length != 2
-                    comparator = cmd_array.shift()
-                    arg = cmd_array.shift().to_i
-                    return_value = true if (result.size.send(comparator, arg))
-                when "include":
+        case verb
+            when "size":
+                fail("Invalid command: #{cmd_array.join(" ")}") if cmd_array.length != 2
+                comparator = cmd_array.shift()
+                arg = cmd_array.shift().to_i
+                return_value = true if (result.size.send(comparator, arg))
+            when "include":
+                arg = cmd_array.join(" ")
+                return_value = result.include?(arg)
+            when "!include"
+                arg = cmd_array.join(" ")
+                return_value = !(result.include?(arg))
+            when "==":
+                begin
                     arg = cmd_array.join(" ")
-                    return_value = true if result.include?(arg)
-                when "==":
-                    begin
-                        arg = cmd_array.join(" ")
-                        new_array = eval arg
-                        return_value = true if result == new_array
-                    rescue
-                        fail("Invalid array in command: #{cmd_array.join(" ")}")
-                    end
-            end
+                    new_array = eval arg
+                    return_value = true if result == new_array
+                rescue
+                    fail("Invalid array in command: #{cmd_array.join(" ")}")
+                end
+            else
+                fail("Can not use the operator #{verb} with matches")
         end
         return_value
-    end    
+    end
+
+    # Used by the need_to_run? method to process match filters. Returns
+    # true if there is a match on the values returnd by a match, false if otherwise
+    def process_match_value(cmd_array)
+
+        return_value = false
+
+        #validate and tear apart the command
+        fail("Invalid command: #{cmd_array.join(" ")}") if cmd_array.length < 4
+        cmd = cmd_array.shift()
+        path = cmd_array.shift()
+        verb = cmd_array.shift()
+
+        #Get the values from augeas
+        aug = open_augeas()
+        result = aug.match(path) || []
+        values = result.collect {|item| aug.get(item)}
+        puts(values)
+        # Now do the work
+        case verb
+            when "include":
+                arg = cmd_array.join(" ")
+                return_value = values.include?(arg)
+            when "!include"
+                arg = cmd_array.join(" ")
+                return_value = !(values.include?(arg))
+            else
+                fail("Can not use the operator #{verb} with matches")
+        end
+        return_value
+    end     
     
     # Determines if augeas acutally needs to run.
     def need_to_run?
@@ -147,6 +182,7 @@ Puppet::Type.type(:augeas).provide(:augeas) do
                 case command
                     when "get" then return_value = process_get(cmd_array)
                     when "match" then return_value = process_match(cmd_array)
+                    when "matchValue" then return_value = process_match_value(cmd_array)                    
                 end
             rescue Exception => e
                 fail("Error sending command '#{command}' with params #{cmd_array[1..-1].inspect}/#{e.message}")

Reply via email to