summaryrefslogtreecommitdiffstats
path: root/lib/puppet/provider
diff options
context:
space:
mode:
Diffstat (limited to 'lib/puppet/provider')
-rw-r--r--lib/puppet/provider/augeas/augeas.rb119
-rw-r--r--lib/puppet/provider/nameservice/directoryservice.rb4
-rw-r--r--lib/puppet/provider/service/gentoo.rb2
-rwxr-xr-xlib/puppet/provider/service/redhat.rb8
-rw-r--r--lib/puppet/provider/ssh_authorized_key/parsed.rb33
-rw-r--r--lib/puppet/provider/user/useradd.rb2
6 files changed, 126 insertions, 42 deletions
diff --git a/lib/puppet/provider/augeas/augeas.rb b/lib/puppet/provider/augeas/augeas.rb
index efa8c2a3c..841bdc6c1 100644
--- a/lib/puppet/provider/augeas/augeas.rb
+++ b/lib/puppet/provider/augeas/augeas.rb
@@ -20,13 +20,17 @@
require 'augeas' if Puppet.features.augeas?
Puppet::Type.type(:augeas).provide(:augeas) do
-#class Puppet::Provider::Augeas < Puppet::Provider
include Puppet::Util
confine :true => Puppet.features.augeas?
has_features :parse_commands, :need_to_run?,:execute_changes
+ SAVE_NOOP = "noop"
+ SAVE_OVERWRITE = "overwrite"
+
+ attr_accessor :aug
+
# Extracts an 2 dimensional array of commands which are in the
# form of command path value.
# The input can be
@@ -72,13 +76,29 @@ Puppet::Type.type(:augeas).provide(:augeas) do
return commands
end
+
def open_augeas
- flags = 0
- (flags = 1 << 2 ) if self.resource[:type_check] == :true
- root = self.resource[:root]
- load_path = self.resource[:load_path]
- debug("Opening augeas with root #{root}, lens path #{load_path}, flags #{flags}")
- Augeas.open(root, load_path,flags)
+ if (@aug.nil?)
+ flags = 0
+ (flags = 1 << 2 ) if self.resource[:type_check] == :true
+ root = self.resource[:root]
+ load_path = self.resource[:load_path]
+ debug("Opening augeas with root #{root}, lens path #{load_path}, flags #{flags}")
+ @aug = Augeas.open(root, load_path,flags)
+
+ if (self.get_augeas_version() >= "0.3.6")
+ debug("Augeas version #{self.get_augeas_version()} is installed")
+ end
+ end
+ @aug
+ end
+
+ def close_augeas
+ if (!@aug.nil?)
+ @aug.close()
+ debug("Closed the augeas connection")
+ @aug = nil;
+ end
end
# Used by the need_to_run? method to process get filters. Returns
@@ -95,8 +115,7 @@ Puppet::Type.type(:augeas).provide(:augeas) do
arg = cmd_array.join(" ")
#check the value in augeas
- aug = open_augeas()
- result = aug.get(path) || ''
+ result = @aug.get(path) || ''
unless result.nil?
case comparator
when "!="
@@ -124,10 +143,9 @@ Puppet::Type.type(:augeas).provide(:augeas) do
verb = cmd_array.shift()
#Get the values from augeas
- aug = open_augeas()
- result = aug.match(path) || ''
+ result = @aug.match(path) || ''
# Now do the work
- if (!result.nil?)
+ unless (result.nil?)
case verb
when "size"
fail("Invalid command: #{cmd_array.join(" ")}") if cmd_array.length != 2
@@ -150,9 +168,24 @@ Puppet::Type.type(:augeas).provide(:augeas) do
return_value
end
+ def get_augeas_version
+ return @aug.get("/augeas/version") || ""
+ end
+
+ def set_augeas_save_mode(mode)
+ return @aug.set("/augeas/save", mode)
+ end
+
+ def files_changed?
+ saved_files = @aug.match("/augeas/events/saved")
+ return saved_files.size() > 0
+ end
+
# Determines if augeas acutally needs to run.
def need_to_run?
+ force = resource[:force]
return_value = true
+ self.open_augeas()
filter = resource[:onlyif]
unless (filter == "")
cmd_array = filter.split
@@ -168,15 +201,53 @@ Puppet::Type.type(:augeas).provide(:augeas) do
fail("Error sending command '#{command}' with params #{cmd_array[1..-1].inspect}/#{e.message}")
end
end
- return_value
+
+ unless (force)
+ # If we have a verison of augeas which is at least 0.3.6 then we
+ # can make the changes now, see if changes were made, and
+ # actually do the save.
+ if ((return_value) and (self.get_augeas_version() >= "0.3.6"))
+ debug("Will attempt to save and only run if files changed")
+ self.set_augeas_save_mode(SAVE_NOOP)
+ self.do_execute_changes()
+ save_result = @aug.save()
+ saved_files = @aug.match("/augeas/events/saved")
+ if ((save_result) and (not files_changed?))
+ debug("Skipping becuase no files were changed")
+ return_value = false
+ else
+ debug("Files changed, should execute")
+ end
+ end
+ end
+ self.close_augeas()
+ return return_value
end
- # Actually execute the augeas changes.
def execute_changes
- aug = open_augeas
- commands = resource[:changes]
+ # Re-connect to augeas, and re-execute the changes
+ self.open_augeas()
+ if (self.get_augeas_version() >= "0.3.6")
+ self.set_augeas_save_mode(SAVE_OVERWRITE)
+ end
+
+ self.do_execute_changes()
+
+ success = @aug.save()
+ if (success != true)
+ fail("Save failed with return code #{success}")
+ end
+ self.close_augeas()
+
+ return :executed
+ end
+
+ # Actually execute the augeas changes.
+ def do_execute_changes
+ commands = resource[:changes].clone()
context = resource[:context]
commands.each do |cmd_array|
+ cmd_array = cmd_array.clone()
fail("invalid command #{cmd_array.join[" "]}") if cmd_array.length < 2
command = cmd_array[0]
cmd_array.shift()
@@ -192,23 +263,22 @@ Puppet::Type.type(:augeas).provide(:augeas) do
aug.rm(cmd_array[0])
when "clear"
cmd_array[0]=File.join(context, cmd_array[0])
- debug("sending command '#{command}' with params #{cmd_array.inspect}")
- aug.clear(cmd_array[0])
+ debug("sending command '#{command}' with params #{cmd_array.inspect}")
+ @aug.clear(cmd_array[0])
when "insert", "ins"
-
ext_array = cmd_array[1].split(" ") ;
if cmd_array.size < 2 or ext_array.size < 2
fail("ins requires 3 parameters")
end
label = cmd_array[0]
where = ext_array[0]
- path = File.join(context, ext_array[1])
+ path = File.join(context, ext_array[1])
case where
when "before"; before = true
when "after"; before = false
else fail("Invalid value '#{where}' for where param")
end
- debug("sending command '#{command}' with params #{[label, where, path].inspect()}")
+ debug("sending command '#{command}' with params #{[label, where, path].inspect()}")
aug.insert(path, label, before)
else fail("Command '#{command}' is not supported")
end
@@ -216,12 +286,5 @@ Puppet::Type.type(:augeas).provide(:augeas) do
fail("Error sending command '#{command}' with params #{cmd_array.inspect}/#{e.message}")
end
end
- success = aug.save()
- if (success != true)
- fail("Save failed with return code #{success}")
- end
-
- return :executed
end
-
end
diff --git a/lib/puppet/provider/nameservice/directoryservice.rb b/lib/puppet/provider/nameservice/directoryservice.rb
index 07b01bbe0..cd1e442d5 100644
--- a/lib/puppet/provider/nameservice/directoryservice.rb
+++ b/lib/puppet/provider/nameservice/directoryservice.rb
@@ -320,14 +320,14 @@ class DirectoryService < Puppet::Provider::NameService
def self.get_password(guid)
password_hash = nil
password_hash_file = "#{@@password_hash_dir}/#{guid}"
- if File.exists?(password_hash_file)
+ if File.exists?(password_hash_file) and File.file?(password_hash_file)
if not File.readable?(password_hash_file)
raise Puppet::Error("Could not read password hash file at #{password_hash_file} for #{@resource[:name]}")
end
f = File.new(password_hash_file)
password_hash = f.read
f.close
- end
+ end
password_hash
end
diff --git a/lib/puppet/provider/service/gentoo.rb b/lib/puppet/provider/service/gentoo.rb
index 4067dee5e..d62df1a38 100644
--- a/lib/puppet/provider/service/gentoo.rb
+++ b/lib/puppet/provider/service/gentoo.rb
@@ -38,7 +38,7 @@ Puppet::Type.type(:service).provide :gentoo, :parent => :init do
return :false unless line
# If it's enabled then it will print output showing service | runlevel
- if output =~ /#{@resource[:name]}\s*\|\s*default/
+ if output =~ /#{@resource[:name]}\s*\|\s*(boot|default)/
return :true
else
return :false
diff --git a/lib/puppet/provider/service/redhat.rb b/lib/puppet/provider/service/redhat.rb
index 031db46c1..f31903e84 100755
--- a/lib/puppet/provider/service/redhat.rb
+++ b/lib/puppet/provider/service/redhat.rb
@@ -73,12 +73,12 @@ Puppet::Type.type(:service).provide :redhat, :parent => :init do
end
end
- def start
- service(@resource[:name], "start")
+ def startcmd
+ [command(:service), @resource[:name], "start"]
end
- def stop
- service(@resource[:name], "stop")
+ def stopcmd
+ [command(:service), @resource[:name], "stop"]
end
end
diff --git a/lib/puppet/provider/ssh_authorized_key/parsed.rb b/lib/puppet/provider/ssh_authorized_key/parsed.rb
index 5604ba32a..6df7f8ae0 100644
--- a/lib/puppet/provider/ssh_authorized_key/parsed.rb
+++ b/lib/puppet/provider/ssh_authorized_key/parsed.rb
@@ -36,13 +36,34 @@ Puppet::Type.type(:ssh_authorized_key).provide(:parsed,
:rts => /^\s+/,
:match => /^(?:(.+) )?(\d+) (\d+) (\d+)(?: (.+))?$/
- def prefetch
- # This was done in the type class but path expansion was failing for
- # not yet existing users, the only workaround I found was to move that
- # in the provider.
- @resource[:target] = target
+ def target
+ @resource.should(:target)
+ end
- super
+ def user
+ @resource.should(:user)
+ end
+
+ def dir_perm
+ # Determine correct permission for created directory and file
+ # we can afford more restrictive permissions when the user is known
+ if target
+ if user
+ 0700
+ else
+ 0755
+ end
+ end
+ end
+
+ def file_perm
+ if target
+ if user
+ 0600
+ else
+ 0644
+ end
+ end
end
def target
diff --git a/lib/puppet/provider/user/useradd.rb b/lib/puppet/provider/user/useradd.rb
index 6996dd69a..15b3b1379 100644
--- a/lib/puppet/provider/user/useradd.rb
+++ b/lib/puppet/provider/user/useradd.rb
@@ -31,7 +31,7 @@ Puppet::Type.type(:user).provide :useradd, :parent => Puppet::Provider::NameServ
cmd = []
if @resource.managehome?
cmd << "-m"
- elsif %w{Fedora RedHat}.include?(Facter.value("operatingsystem"))
+ elsif %w{Fedora RedHat CentOS OEL OVS}.include?(Facter.value("operatingsystem"))
cmd << "-M"
end
cmd