Moved generic puppet plugins from custom/lib under puppet/lib
This commit is contained in:
parent
dc5cd90bde
commit
2f7b76a47b
7 changed files with 0 additions and 0 deletions
10
puppet/lib/facter/augeas.rb
Normal file
10
puppet/lib/facter/augeas.rb
Normal file
|
@ -0,0 +1,10 @@
|
|||
Facter.add("augeas") do
|
||||
setcode do
|
||||
begin
|
||||
require "augeas.rb"
|
||||
true
|
||||
rescue LoadError
|
||||
false
|
||||
end
|
||||
end
|
||||
end
|
27
puppet/lib/facter/console.rb
Normal file
27
puppet/lib/facter/console.rb
Normal file
|
@ -0,0 +1,27 @@
|
|||
Facter.add('console') do
|
||||
confine :kernel => :linux
|
||||
setcode do
|
||||
console = 'vga'
|
||||
File.readlines("/proc/cmdline").each do |line|
|
||||
if m = line.match(/console=(\S*)/)
|
||||
console = m[1]
|
||||
end
|
||||
end
|
||||
console
|
||||
end
|
||||
end
|
||||
|
||||
Facter.add('console') do
|
||||
confine :kernel => :openbsd
|
||||
setcode do
|
||||
console = 'vga'
|
||||
if File.exists?("/etc/boot.conf")
|
||||
File.readlines("/etc/boot.conf").each do |line|
|
||||
if m = line.match(/set\s+tty\s+(\S+)/)
|
||||
console = m[1]
|
||||
end
|
||||
end
|
||||
end
|
||||
console
|
||||
end
|
||||
end
|
8
puppet/lib/facter/environment.rb
Normal file
8
puppet/lib/facter/environment.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
ENV.each do |k,v|
|
||||
next if not k.downcase =~ /^puppet_/
|
||||
Facter.add("env_#{k.downcase}".to_sym) do
|
||||
setcode do
|
||||
v
|
||||
end
|
||||
end
|
||||
end
|
15
puppet/lib/facter/external.rb
Normal file
15
puppet/lib/facter/external.rb
Normal file
|
@ -0,0 +1,15 @@
|
|||
# Load external key-value facts for facter < 1.7.
|
||||
if Facter.value(:facterversion).match(/^1\.[56]/) and
|
||||
File.directory?("/etc/facter/facts.d")
|
||||
Dir.glob("/etc/facter/facts.d/*.txt") do |txt|
|
||||
File.readlines(txt).each do |line|
|
||||
kv = line.strip.split("=", 2)
|
||||
continue if kv.length != 2
|
||||
Facter.add(kv[0].to_sym) do
|
||||
setcode do
|
||||
kv[1]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
10
puppet/lib/facter/homename.rb
Normal file
10
puppet/lib/facter/homename.rb
Normal file
|
@ -0,0 +1,10 @@
|
|||
require 'puppet'
|
||||
|
||||
Facter.add('homename') do
|
||||
setcode do
|
||||
if Facter.value('puppetversion').to_i < 3
|
||||
Puppet.parse_config
|
||||
end
|
||||
Puppet.settings.value('certname')
|
||||
end
|
||||
end
|
10
puppet/lib/facter/puppet_ssldir.rb
Normal file
10
puppet/lib/facter/puppet_ssldir.rb
Normal file
|
@ -0,0 +1,10 @@
|
|||
require 'puppet'
|
||||
|
||||
Facter.add('puppet_ssldir') do
|
||||
setcode do
|
||||
if Facter.value('puppetversion').to_i < 3
|
||||
Puppet.parse_config
|
||||
end
|
||||
Puppet.settings.value('ssldir')
|
||||
end
|
||||
end
|
150
puppet/lib/puppet/provider/service/openbsd.rb
Normal file
150
puppet/lib/puppet/provider/service/openbsd.rb
Normal file
|
@ -0,0 +1,150 @@
|
|||
# Manage OpenBSD services. Enable/disable using /etc/rc.conf.local
|
||||
|
||||
Puppet::Type.type(:service).provide :openbsd, :parent => :base do
|
||||
|
||||
desc "OpenBSD service management."
|
||||
|
||||
confine :operatingsystem => :openbsd
|
||||
defaultfor :operatingsystem => :openbsd
|
||||
|
||||
def rc_dir() '/etc/rc.d' end
|
||||
def rcconf() '/etc/rc.conf' end
|
||||
def rcconf_local() '/etc/rc.conf.local' end
|
||||
|
||||
def pkg_scripts_var()
|
||||
if Facter["operatingsystemrelease"].value == "4.9"
|
||||
return "rc_scripts"
|
||||
else
|
||||
return "pkg_scripts"
|
||||
end
|
||||
end
|
||||
|
||||
def rcscript
|
||||
return File.join(rc_dir, @resource[:name])
|
||||
end
|
||||
|
||||
def rcvar
|
||||
name = @resource[:name]
|
||||
File.open(rcconf).each do |line|
|
||||
if line =~ /^#{name}(_flags)?=/
|
||||
line = line.sub(/#.*/, "")
|
||||
return line.strip.split("=", 2)
|
||||
end
|
||||
end
|
||||
nil
|
||||
end
|
||||
|
||||
def rcvar_local
|
||||
name = @resource[:name]
|
||||
File.open(rcconf_local).each do |line|
|
||||
if line =~ /^#{name}(_flags)?=/
|
||||
line = line.sub(/#.*/, "")
|
||||
return line.strip.split("=", 2)
|
||||
end
|
||||
end
|
||||
nil
|
||||
end
|
||||
|
||||
def rcvar_name
|
||||
[self.rcvar_local, self.rcvar].each do |rcvar|
|
||||
return rcvar[0] unless rcvar.nil?
|
||||
end
|
||||
"%s_flags" % @resource[:name]
|
||||
end
|
||||
|
||||
def rcvar_value
|
||||
[self.rcvar_local, self.rcvar].each do |rcvar|
|
||||
return rcvar[1].gsub(/"?([^"]*)"?/, '\1') unless rcvar.nil?
|
||||
end
|
||||
nil
|
||||
end
|
||||
|
||||
def pkg_scripts
|
||||
File.open(rcconf_local).each do |line|
|
||||
if line =~ /^#{pkg_scripts_var}=/
|
||||
return line.strip.gsub(/#{pkg_scripts_var}="?([^"]*)"?/, '\1').split
|
||||
end
|
||||
end
|
||||
Array.new
|
||||
end
|
||||
|
||||
def enabled?
|
||||
name = @resource[:name]
|
||||
rcvar = self.rcvar
|
||||
rcvar_name = self.rcvar_name
|
||||
rcvar_value = self.rcvar_value
|
||||
pkg_scripts = self.pkg_scripts
|
||||
if rcvar_name.end_with?("_flags")
|
||||
return :false if rcvar.nil? and not pkg_scripts.include?(name)
|
||||
return :false if rcvar_value.nil? or rcvar_value == "NO"
|
||||
else
|
||||
return :false if rcvar_value != "YES"
|
||||
end
|
||||
:true
|
||||
end
|
||||
|
||||
def enable
|
||||
name = @resource[:name]
|
||||
rcvar = self.rcvar
|
||||
rcvar_name = self.rcvar_name
|
||||
rcvar_value = ""
|
||||
pkg_scripts = self.pkg_scripts
|
||||
start = @resource[:start]
|
||||
binary = @resource[:binary]
|
||||
s = ""
|
||||
File.open(rcconf_local).each do |line|
|
||||
next if line =~ /^(#{rcvar_name}|#{pkg_scripts_var})=/
|
||||
s += line
|
||||
end
|
||||
unless start.nil?
|
||||
if binary.nil?
|
||||
rcvar_value = start[/^\S+\s*(.*)/, 1]
|
||||
else
|
||||
rcvar_value = start[/^#{binary}\s*(.*)/, 1]
|
||||
end
|
||||
end
|
||||
if rcvar_name.end_with?("_flags")
|
||||
s += "%s=\"%s\"\n" % [rcvar_name, rcvar_value]
|
||||
else
|
||||
s += "%s=YES\n" % rcvar_name
|
||||
end
|
||||
pkg_scripts << name if rcvar.nil? and not pkg_scripts.include?(name)
|
||||
s += "#{pkg_scripts_var}=\"%s\"\n" % pkg_scripts.join(" ")
|
||||
File.open(rcconf_local, "w") { |f| f << s }
|
||||
end
|
||||
|
||||
def disable
|
||||
name = @resource[:name]
|
||||
rcvar = self.rcvar
|
||||
rcvar_name = self.rcvar_name
|
||||
pkg_scripts = self.pkg_scripts
|
||||
s = ""
|
||||
File.open(rcconf_local).each do |line|
|
||||
next if line =~ /^(#{rcvar_name}|#{pkg_scripts_var})=/
|
||||
s += line
|
||||
end
|
||||
s += "%s=NO\n" % rcvar_name unless rcvar.nil?
|
||||
pkg_scripts.delete(name)
|
||||
s += "#{pkg_scripts_var}=\"%s\"\n" % pkg_scripts.join(" ")
|
||||
File.open(rcconf_local, "w") { |f| f << s }
|
||||
end
|
||||
|
||||
def startcmd
|
||||
if File.exists?(self.rcscript)
|
||||
[self.rcscript, :start]
|
||||
end
|
||||
end
|
||||
|
||||
def stopcmd
|
||||
if File.exists?(self.rcscript)
|
||||
[self.rcscript, :stop]
|
||||
end
|
||||
end
|
||||
|
||||
def statuscmd
|
||||
if File.exists?(self.rcscript)
|
||||
[self.rcscript, :check]
|
||||
end
|
||||
end
|
||||
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue