It's been bugging me for a while that when I run Puppet from the command line, I don't see the changes that Augeas does/will make as we do with the file type.

There seem to be 2 requests for this:
https://projects.puppetlabs.com/issues/2728
http://projects.puppetlabs.com/issues/5400

I haven't had a go at writing any tests yet.
The changes work for me on the master and 2.6.next branches.

Regards

On 18/03/11 11:11 PM, Michael Knox wrote:
From: Michael Knox<m...@sysam.com.au>

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<michael.knox...@gmail.com>
---
  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

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

Reply via email to