From: Michael Knox <[email protected]>

Utilising Augeas's SAVE_NEWFILE mode (similar to augtool -n) to
determine the changes that will be made be made by Augeas.
Output a unified diff to info

Signed-off-by: Mike Knox <[email protected]>
---
 lib/puppet/provider/augeas/augeas.rb |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/lib/puppet/provider/augeas/augeas.rb 
b/lib/puppet/provider/augeas/augeas.rb
index 427d997..7a8b4d1 100644
--- a/lib/puppet/provider/augeas/augeas.rb
+++ b/lib/puppet/provider/augeas/augeas.rb
@@ -22,6 +22,7 @@ require 'strscan'
 
 Puppet::Type.type(:augeas).provide(:augeas) do
     include Puppet::Util
+    include Puppet::Util::Diff
 
     confine :true => Puppet.features.augeas?
 
@@ -29,6 +30,8 @@ Puppet::Type.type(:augeas).provide(:augeas) do
 
     SAVE_NOOP = "noop"
     SAVE_OVERWRITE = "overwrite"
+    SAVE_NEWFILE = "newfile"
+    SAVE_BACKUP = "backup"
 
     COMMANDS = {
       "set" => [ :path, :string ],
@@ -286,14 +289,19 @@ Puppet::Type.type(:augeas).provide(:augeas) do
                 # actually do the save.
                 if return_value and get_augeas_version >= "0.3.6"
                     debug("Will attempt to save and only run if files changed")
-                    set_augeas_save_mode(SAVE_NOOP)
+                    set_augeas_save_mode(SAVE_NEWFILE)
                     do_execute_changes
                     save_result = @aug.save
-                    saved_files = @aug.match("/augeas/events/saved")
+                    saved_files = @aug.get("/augeas/events/saved")
                     if save_result and not files_changed?
                         debug("Skipping because no files were changed")
                         return_value = false
                     else
+                        saved_files.each do |tmp_file|
+                          saved_file = tmp_file.sub(/^\/files/, '')
+                          info(diff(saved_file, saved_file + ".augnew"))
+                          File.delete(saved_file + ".augnew")
+                        end
                         debug("Files changed, should execute")
                     end
                 end
-- 
1.7.3.5

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en.

Reply via email to