summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/puppet/agent.rb4
-rw-r--r--lib/puppet/application/queue.rb2
-rw-r--r--lib/puppet/indirector/node/exec.rb2
-rw-r--r--lib/puppet/indirector/node/ldap.rb6
-rw-r--r--lib/puppet/parser/compiler.rb2
-rw-r--r--lib/puppet/parser/functions/extlookup.rb275
-rw-r--r--lib/puppet/parser/functions/require.rb2
-rwxr-xr-xlib/puppet/provider/package/apt.rb4
-rw-r--r--lib/puppet/resource.rb2
-rw-r--r--lib/puppet/resource/type.rb2
-rw-r--r--lib/puppet/type.rb2
-rwxr-xr-xlib/puppet/type/file/content.rb6
-rwxr-xr-xlib/puppet/type/file/source.rb10
-rw-r--r--lib/puppet/type/yumrepo.rb12
14 files changed, 178 insertions, 153 deletions
diff --git a/lib/puppet/agent.rb b/lib/puppet/agent.rb
index 52acc64aa..47dd44a0e 100644
--- a/lib/puppet/agent.rb
+++ b/lib/puppet/agent.rb
@@ -37,7 +37,9 @@ class Puppet::Agent
with_client do |client|
begin
sync.synchronize { lock { result = client.run(*args) } }
- rescue => detail
+ rescue SystemExit,NoMemoryError
+ raise
+ rescue Exception => detail
puts detail.backtrace if Puppet[:trace]
Puppet.err "Could not run #{client_class}: #{detail}"
end
diff --git a/lib/puppet/application/queue.rb b/lib/puppet/application/queue.rb
index 6c90ca0a1..239f6b2ad 100644
--- a/lib/puppet/application/queue.rb
+++ b/lib/puppet/application/queue.rb
@@ -38,7 +38,7 @@ class Puppet::Application::Queue < Puppet::Application
option("--verbose","-v")
def main
- require 'lib/puppet/indirector/catalog/queue' # provides Puppet::Indirector::Queue.subscribe
+ require 'puppet/indirector/catalog/queue' # provides Puppet::Indirector::Queue.subscribe
Puppet.notice "Starting puppetqd #{Puppet.version}"
Puppet::Resource::Catalog::Queue.subscribe do |catalog|
# Once you have a Puppet::Resource::Catalog instance, calling save on it should suffice
diff --git a/lib/puppet/indirector/node/exec.rb b/lib/puppet/indirector/node/exec.rb
index c3e690943..6e065c6f3 100644
--- a/lib/puppet/indirector/node/exec.rb
+++ b/lib/puppet/indirector/node/exec.rb
@@ -3,7 +3,7 @@ require 'puppet/indirector/exec'
class Puppet::Node::Exec < Puppet::Indirector::Exec
desc "Call an external program to get node information. See
- the `ExternalNodes`:trac: page for more information."
+ the [External Nodes](http://docs.puppetlabs.com/guides/external_nodes.html) page for more information."
include Puppet::Util
def command
diff --git a/lib/puppet/indirector/node/ldap.rb b/lib/puppet/indirector/node/ldap.rb
index ecebc8279..5fd738511 100644
--- a/lib/puppet/indirector/node/ldap.rb
+++ b/lib/puppet/indirector/node/ldap.rb
@@ -3,9 +3,9 @@ require 'puppet/indirector/ldap'
class Puppet::Node::Ldap < Puppet::Indirector::Ldap
desc "Search in LDAP for node configuration information. See
- the `LdapNodes`:trac: page for more information. This will first
+ the [LDAP Nodes](http://projects.puppetlabs.com/projects/puppet/wiki/Ldap_Nodes) page for more information. This will first
search for whatever the certificate name is, then (if that name
- contains a '.') for the short name, then 'default'."
+ contains a `.`) for the short name, then `default`."
# The attributes that Puppet class information is stored in.
def class_attributes
@@ -34,7 +34,7 @@ class Puppet::Node::Ldap < Puppet::Indirector::Ldap
node = nil
names.each do |name|
next unless info = name2hash(name)
-
+
break if node = info2node(request.key, info)
end
diff --git a/lib/puppet/parser/compiler.rb b/lib/puppet/parser/compiler.rb
index 7504b276b..e1227e753 100644
--- a/lib/puppet/parser/compiler.rb
+++ b/lib/puppet/parser/compiler.rb
@@ -71,7 +71,7 @@ class Puppet::Parser::Compiler
raise ArgumentError, "Could not find stage #{resource[:stage] || :main} specified by #{resource}"
end
- resource[:stage] ||= stage.title
+ resource[:stage] ||= stage.title unless stage.title == :main
@catalog.add_edge(stage, resource)
end
diff --git a/lib/puppet/parser/functions/extlookup.rb b/lib/puppet/parser/functions/extlookup.rb
index a4786f5da..63d49e563 100644
--- a/lib/puppet/parser/functions/extlookup.rb
+++ b/lib/puppet/parser/functions/extlookup.rb
@@ -1,166 +1,157 @@
-# Puppet External Data Sources
-#
-# This is a parser function to read data from external files, this version
-# uses CSV files but the concept can easily be adjust for databases, yaml
-# or any other queryable data source.
-#
-# The object of this is to make it obvious when it's being used, rather than
-# magically loading data in when an module is loaded I prefer to look at the code
-# and see statements like:
-#
-# $snmp_contact = extlookup("snmp_contact")
-#
-# The above snippet will load the snmp_contact value from CSV files, this in its
-# own is useful but a common construct in puppet manifests is something like this:
-#
-# case $domain {
-# "myclient.com": { $snmp_contact = "John Doe <john@myclient.com>" }
-# default: { $snmp_contact = "My Support <support@my.com>" }
-# }
-#
-# Over time there will be a lot of this kind of thing spread all over your manifests
-# and adding an additional client involves grepping through manifests to find all the
-# places where you have constructs like this.
-#
-# This is a data problem and shouldn't be handled in code, a using this function you
-# can do just that.
-#
-# First you configure it in site.pp:
-# $extlookup_datadir = "/etc/puppet/manifests/extdata"
-# $extlookup_precedence = ["%{fqdn}", "domain_%{domain}", "common"]
-#
-# The array tells the code how to resolve values, first it will try to find it in
-# web1.myclient.com.csv then in domain_myclient.com.csv and finally in common.csv
-#
-# Now create the following data files in /etc/puppet/manifests/extdata
-#
-# domain_myclient.com.csv:
-# snmp_contact,John Doe <john@myclient.com>
-# root_contact,support@%{domain}
-# client_trusted_ips,192.168.1.130,192.168.10.0/24
-#
-# common.csv:
-# snmp_contact,My Support <support@my.com>
-# root_contact,support@my.com
-#
-# Now you can replace the case statement with the simple single line to achieve
-# the exact same outcome:
-#
-# $snmp_contact = extlookup("snmp_contact")
-#
-# The obove code shows some other features, you can use any fact or variable that
-# is in scope by simply using %{varname} in your data files, you can return arrays
-# by just having multiple values in the csv after the initial variable name.
-#
-# In the event that a variable is nowhere to be found a critical error will be raised
-# that will prevent your manifest from compiling, this is to avoid accidentally putting
-# in empty values etc. You can however specify a default value:
-#
-# $ntp_servers = extlookup("ntp_servers", "1.${country}.pool.ntp.org")
-#
-# In this case it will default to "1.${country}.pool.ntp.org" if nothing is defined in
-# any data file.
-#
-# You can also specify an additional data file to search first before any others at use
-# time, for example:
-#
-# $version = extlookup("rsyslog_version", "present", "packages")
-#
-# package{"rsyslog": ensure => $version }
-#
-# This will look for a version configured in packages.csv and then in the rest as configured
-# by $extlookup_precedence if it's not found anywhere it will default to "present", this kind
-# of use case makes puppet a lot nicer for managing large amounts of packages since you do not
-# need to edit a load of manifests to do simple things like adjust a desired version number.
-#
-# For more information on installing and writing your own custom functions see:
-# http://docs.puppetlabs.com/guides/custom_functions.html
-#
-# For further help contact Volcane on #puppet
require 'csv'
module Puppet::Parser::Functions
- newfunction(:extlookup, :type => :rvalue) do |args|
- key = args[0]
-
- default = args[1]
- datafile = args[2]
-
- raise Puppet::ParseError, ("extlookup(): wrong number of arguments (#{args.length}; must be <= 3)") if args.length > 3
-
- extlookup_datadir = lookupvar('extlookup_datadir')
- extlookup_precedence = Array.new
-
- # precedence values can have variables embedded in them
- # in the form %{fqdn}, you could for example do
- #
- # $extlookup_precedence = ["hosts/%{fqdn}", "common"]
- #
- # this will result in /path/to/extdata/hosts/your.box.com.csv
- # being searched.
- #
- # This is for back compatibility to interpolate variables with %.
- # % interpolation is a workaround for a problem that has been fixed: Puppet variable
- # interpolation at top scope used to only happen on each run
- extlookup_precedence = lookupvar('extlookup_precedence').collect do |var|
- var.gsub(/%\{(.+?)\}/) do |capture|
- lookupvar($1)
- end
- end
+ newfunction(:extlookup,
+ :type => :rvalue,
+ :doc => "This is a parser function to read data from external files, this version
+uses CSV files but the concept can easily be adjust for databases, yaml
+or any other queryable data source.
- datafiles = Array.new
+The object of this is to make it obvious when it's being used, rather than
+magically loading data in when an module is loaded I prefer to look at the code
+and see statements like:
- # if we got a custom data file, put it first in the array of search files
- if datafile != ""
- datafiles << extlookup_datadir + "/#{datafile}.csv" if File.exists?(extlookup_datadir + "/#{datafile}.csv")
- end
+ $snmp_contact = extlookup(\"snmp_contact\")
+
+The above snippet will load the snmp_contact value from CSV files, this in its
+own is useful but a common construct in puppet manifests is something like this:
+
+ case $domain {
+ \"myclient.com\": { $snmp_contact = \"John Doe <john@myclient.com>\" }
+ default: { $snmp_contact = \"My Support <support@my.com>\" }
+ }
+
+Over time there will be a lot of this kind of thing spread all over your manifests
+and adding an additional client involves grepping through manifests to find all the
+places where you have constructs like this.
+
+This is a data problem and shouldn't be handled in code, a using this function you
+can do just that.
+
+First you configure it in site.pp:
+
+ $extlookup_datadir = \"/etc/puppet/manifests/extdata\"
+ $extlookup_precedence = [\"%{fqdn}\", \"domain_%{domain}\", \"common\"]
+
+The array tells the code how to resolve values, first it will try to find it in
+web1.myclient.com.csv then in domain_myclient.com.csv and finally in common.csv
+
+Now create the following data files in /etc/puppet/manifests/extdata:
+
+ domain_myclient.com.csv:
+ snmp_contact,John Doe <john@myclient.com>
+ root_contact,support@%{domain}
+ client_trusted_ips,192.168.1.130,192.168.10.0/24
+
+ common.csv:
+ snmp_contact,My Support <support@my.com>
+ root_contact,support@my.com
+
+Now you can replace the case statement with the simple single line to achieve
+the exact same outcome:
+
+ $snmp_contact = extlookup(\"snmp_contact\")
+
+The obove code shows some other features, you can use any fact or variable that
+is in scope by simply using %{varname} in your data files, you can return arrays
+by just having multiple values in the csv after the initial variable name.
+
+In the event that a variable is nowhere to be found a critical error will be raised
+that will prevent your manifest from compiling, this is to avoid accidentally putting
+in empty values etc. You can however specify a default value:
+
+ $ntp_servers = extlookup(\"ntp_servers\", \"1.${country}.pool.ntp.org\")
+
+In this case it will default to \"1.${country}.pool.ntp.org\" if nothing is defined in
+any data file.
+
+You can also specify an additional data file to search first before any others at use
+time, for example:
+
+ $version = extlookup(\"rsyslog_version\", \"present\", \"packages\")
+ package{\"rsyslog\": ensure => $version }
- extlookup_precedence.each do |d|
- datafiles << extlookup_datadir + "/#{d}.csv"
+This will look for a version configured in packages.csv and then in the rest as configured
+by $extlookup_precedence if it's not found anywhere it will default to `present`, this kind
+of use case makes puppet a lot nicer for managing large amounts of packages since you do not
+need to edit a load of manifests to do simple things like adjust a desired version number.
+
+Precedence values can have variables embedded in them in the form %{fqdn}, you could for example do:
+
+ $extlookup_precedence = [\"hosts/%{fqdn}\", \"common\"]
+
+This will result in /path/to/extdata/hosts/your.box.com.csv being searched.
+
+This is for back compatibility to interpolate variables with %. % interpolation is a workaround for a problem that has been fixed: Puppet variable interpolation at top scope used to only happen on each run.") do |args|
+
+ key = args[0]
+
+ default = args[1]
+ datafile = args[2]
+
+ raise Puppet::ParseError, ("extlookup(): wrong number of arguments (#{args.length}; must be <= 3)") if args.length > 3
+
+ extlookup_datadir = lookupvar('extlookup_datadir')
+ extlookup_precedence = Array.new
+
+ extlookup_precedence = lookupvar('extlookup_precedence').collect do |var|
+ var.gsub(/%\{(.+?)\}/) do |capture|
+ lookupvar($1)
end
+ end
- desired = nil
+ datafiles = Array.new
- datafiles.each do |file|
- if desired.nil?
- if File.exists?(file)
- result = CSV.read(file).find_all do |r|
- r[0] == key
- end
+ # if we got a custom data file, put it first in the array of search files
+ if datafile != ""
+ datafiles << extlookup_datadir + "/#{datafile}.csv" if File.exists?(extlookup_datadir + "/#{datafile}.csv")
+ end
+ extlookup_precedence.each do |d|
+ datafiles << extlookup_datadir + "/#{d}.csv"
+ end
- # return just the single result if theres just one,
- # else take all the fields in the csv and build an array
- if result.length > 0
- if result[0].length == 2
- val = result[0][1].to_s
+ desired = nil
- # parse %{}'s in the CSV into local variables using lookupvar()
- while val =~ /%\{(.+?)\}/
- val.gsub!(/%\{#{$1}\}/, lookupvar($1))
- end
+ datafiles.each do |file|
+ if desired.nil?
+ if File.exists?(file)
+ result = CSV.read(file).find_all do |r|
+ r[0] == key
+ end
- desired = val
- elsif result[0].length > 1
- length = result[0].length
- cells = result[0][1,length]
+ # return just the single result if theres just one,
+ # else take all the fields in the csv and build an array
+ if result.length > 0
+ if result[0].length == 2
+ val = result[0][1].to_s
- # Individual cells in a CSV result are a weird data type and throws
- # puppets yaml parsing, so just map it all to plain old strings
- desired = cells.map do |c|
- # parse %{}'s in the CSV into local variables using lookupvar()
- while c =~ /%\{(.+?)\}/
- c.gsub!(/%\{#{$1}\}/, lookupvar($1))
- end
+ # parse %{}'s in the CSV into local variables using lookupvar()
+ while val =~ /%\{(.+?)\}/
+ val.gsub!(/%\{#{$1}\}/, lookupvar($1))
+ end
+
+ desired = val
+ elsif result[0].length > 1
+ length = result[0].length
+ cells = result[0][1,length]
- c.to_s
+ # Individual cells in a CSV result are a weird data type and throws
+ # puppets yaml parsing, so just map it all to plain old strings
+ desired = cells.map do |c|
+ # parse %{}'s in the CSV into local variables using lookupvar()
+ while c =~ /%\{(.+?)\}/
+ c.gsub!(/%\{#{$1}\}/, lookupvar($1))
end
+
+ c.to_s
end
end
end
end
end
+ end
- desired || default or raise Puppet::ParseError, "No match found for '#{key}' in any data file during extlookup()"
+ desired || default or raise Puppet::ParseError, "No match found for '#{key}' in any data file during extlookup()"
end
end
diff --git a/lib/puppet/parser/functions/require.rb b/lib/puppet/parser/functions/require.rb
index f15046b91..64285307e 100644
--- a/lib/puppet/parser/functions/require.rb
+++ b/lib/puppet/parser/functions/require.rb
@@ -12,7 +12,7 @@ relationships between classes. This function is a superset of the
class depends on the required class.
Warning: using require in place of include can lead to unwanted dependency cycles.
-
+
For instance the following manifest, with 'require' instead of 'include' would produce a nasty dependence cycle, because notify imposes a before between File[/foo] and Service[foo]:
class myservice {
diff --git a/lib/puppet/provider/package/apt.rb b/lib/puppet/provider/package/apt.rb
index b6ded39fd..2fc787419 100755
--- a/lib/puppet/provider/package/apt.rb
+++ b/lib/puppet/provider/package/apt.rb
@@ -14,6 +14,10 @@ Puppet::Type.type(:package).provide :apt, :parent => :dpkg, :source => :dpkg do
ENV['DEBIAN_FRONTEND'] = "noninteractive"
+ # disable common apt helpers to allow non-interactive package installs
+ ENV['APT_LISTBUGS_FRONTEND'] = "none"
+ ENV['APT_LISTCHANGES_FRONTEND'] = "none"
+
# A derivative of DPKG; this is how most people actually manage
# Debian boxes, and the only thing that differs is that it can
# install packages from remote sites.
diff --git a/lib/puppet/resource.rb b/lib/puppet/resource.rb
index c4e52af18..39803b077 100644
--- a/lib/puppet/resource.rb
+++ b/lib/puppet/resource.rb
@@ -193,7 +193,7 @@ class Puppet::Resource
end
def resource_type
- @resource_type ||= case type
+ case type
when "Class"; known_resource_types.hostclass(title == :main ? "" : title)
when "Node"; known_resource_types.node(title)
else
diff --git a/lib/puppet/resource/type.rb b/lib/puppet/resource/type.rb
index f6d378512..1d378aaa6 100644
--- a/lib/puppet/resource/type.rb
+++ b/lib/puppet/resource/type.rb
@@ -234,7 +234,7 @@ class Puppet::Resource::Type
end
scope.setvar("title", resource.title) unless set.include? :title
- scope.setvar("name", resource.name) unless set.include? :name
+ scope.setvar("name", resource.name.to_s.downcase) unless set.include? :name
scope.setvar("module_name", module_name) if module_name and ! set.include? :module_name
if caller_name = scope.parent_module_name and ! set.include?(:caller_module_name)
diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb
index 53c23aa32..291179a02 100644
--- a/lib/puppet/type.rb
+++ b/lib/puppet/type.rb
@@ -1031,7 +1031,7 @@ class Type
}
service { sshd:
- subscribe => file[sshdconfig]
+ subscribe => File[sshdconfig]
}
When you use this feature, the parser sets `sshdconfig` as the name,
diff --git a/lib/puppet/type/file/content.rb b/lib/puppet/type/file/content.rb
index 0d0bb5571..b8f30a9c7 100755
--- a/lib/puppet/type/file/content.rb
+++ b/lib/puppet/type/file/content.rb
@@ -161,11 +161,17 @@ module Puppet
}
end
+ def self.standalone?
+ Puppet.settings[:name] == "apply"
+ end
+
def each_chunk_from(source_or_content)
if source_or_content.is_a?(String)
yield source_or_content
elsif source_or_content.nil?
yield read_file_from_filebucket
+ elsif self.class.standalone?
+ yield source_or_content.content
elsif source_or_content.local?
chunk_file_from_disk(source_or_content) { |chunk| yield chunk }
else
diff --git a/lib/puppet/type/file/source.rb b/lib/puppet/type/file/source.rb
index 0e7aac72d..7d03de2b0 100755
--- a/lib/puppet/type/file/source.rb
+++ b/lib/puppet/type/file/source.rb
@@ -94,6 +94,16 @@ module Puppet
metadata && metadata.checksum
end
+ # Look up (if necessary) and return remote content.
+ cached_attr(:content) do
+ raise Puppet::DevError, "No source for content was stored with the metadata" unless metadata.source
+
+ unless tmp = Puppet::FileServing::Content.find(metadata.source)
+ fail "Could not find any content at %s" % metadata.source
+ end
+ tmp.content
+ end
+
# Copy the values from the source to the resource. Yay.
def copy_source_values
devfail "Somehow got asked to copy source values without any metadata" unless metadata
diff --git a/lib/puppet/type/yumrepo.rb b/lib/puppet/type/yumrepo.rb
index 698c077f4..160b2164d 100644
--- a/lib/puppet/type/yumrepo.rb
+++ b/lib/puppet/type/yumrepo.rb
@@ -295,6 +295,12 @@ module Puppet
newvalue(%r{(0|1)}) { }
end
+ newproperty(:http_caching, :parent => Puppet::IniProperty) do
+ desc "Either 'packages' or 'all' or 'none'.\n#{ABSENT_DOC}"
+ newvalue(:absent) { self.should = :absent }
+ newvalue(%r(packages|all|none)) { }
+ end
+
newproperty(:timeout, :parent => Puppet::IniProperty) do
desc "Number of seconds to wait for a connection before timing
out.\n#{ABSENT_DOC}"
@@ -325,6 +331,12 @@ module Puppet
newvalue(%r{[1-9][0-9]?}) { }
end
+ newproperty(:cost, :parent => Puppet::IniProperty) do
+ desc "Cost of this repository.\n#{ABSENT_DOC}"
+ newvalue(:absent) { self.should = :absent }
+ newvalue(%r{\d+}) { }
+ end
+
newproperty(:proxy, :parent => Puppet::IniProperty) do
desc "URL to the proxy server for this repository.\n#{ABSENT_DOC}"
newvalue(:absent) { self.should = :absent }