Also cleaned up a few error messages (unrelated)
---
lib/puppet/application/puppetrun.rb | 12 ++++++-
lib/puppet/daemon.rb | 2 +-
lib/puppet/network/server.rb | 2 +-
lib/puppet/util/runner.rb | 53 +++++++++++++++++++++++++++++++++++
4 files changed, 65 insertions(+), 4 deletions(-)
create mode 100644 lib/puppet/util/runner.rb
diff --git a/lib/puppet/application/puppetrun.rb
b/lib/puppet/application/puppetrun.rb
index 4febcf5..363e0be 100644
--- a/lib/puppet/application/puppetrun.rb
+++ b/lib/puppet/application/puppetrun.rb
@@ -1,5 +1,6 @@
require 'puppet'
require 'puppet/application'
+require 'puppet/util/runner'
Puppet.warning "RubyGems not installed" unless Puppet.features.rubygems?
Puppet.warning "Failed to load ruby LDAP library. LDAP functionality will not
be available" unless Puppet.features.ldap?
@@ -41,7 +42,6 @@ Puppet::Application.new(:puppetrun) do
end
end
-
dispatch do
options[:test] ? :test : :main
end
@@ -55,6 +55,13 @@ Puppet::Application.new(:puppetrun) do
require 'puppet/network/client'
require 'puppet/util/ldap/connection'
+ # the host list may contain globs/regexes, expand it to get
+ # the actual list of hosts to operate on
+ runner_lib = Puppet::Util::Runner.new()
+ @hosts = runner_lib.expand_groups(@hosts)
+ @hosts = runner_lib.expand_hosts(@hosts)
+ puts "Final host list: #{hosts}"
+
todo = @hosts.dup
failures = []
@@ -108,7 +115,7 @@ Puppet::Application.new(:puppetrun) do
if options[:ping]
out = %x{ping -c 1 #{host}}
unless $? == 0
- $stderr.print "Could not contact %s\n" % host
+ $stderr.print "Ping failed, could not contact %s\n" % host
next
end
end
@@ -153,6 +160,7 @@ Puppet::Application.new(:puppetrun) do
@hosts = []
@classes = []
@tags = []
+
end
setup do
diff --git a/lib/puppet/daemon.rb b/lib/puppet/daemon.rb
index 0f538fe..3c7b194 100755
--- a/lib/puppet/daemon.rb
+++ b/lib/puppet/daemon.rb
@@ -44,7 +44,7 @@ class Puppet::Daemon
def create_pidfile
Puppet::Util.sync(Puppet[:name]).synchronize(Sync::EX) do
unless Puppet::Util::Pidlock.new(pidfile).lock
- raise "Could not create PID file: %s" % [pidfile]
+ raise "Could not create PID file, already running?: %s" %
[pidfile]
end
end
end
diff --git a/lib/puppet/network/server.rb b/lib/puppet/network/server.rb
index 01a55df..f926fad 100644
--- a/lib/puppet/network/server.rb
+++ b/lib/puppet/network/server.rb
@@ -34,7 +34,7 @@ class Puppet::Network::Server
def create_pidfile
Puppet::Util.sync(Puppet[:name]).synchronize(Sync::EX) do
unless Puppet::Util::Pidlock.new(pidfile).lock
- raise "Could not create PID file: %s" % [pidfile]
+ raise "Could not create PID file, already running?: %s" %
[pidfile]
end
end
end
diff --git a/lib/puppet/util/runner.rb b/lib/puppet/util/runner.rb
new file mode 100644
index 0000000..601dc7f
--- /dev/null
+++ b/lib/puppet/util/runner.rb
@@ -0,0 +1,53 @@
+# code to support features of the 'puppetrun' application
+#
+# Michael DeHaan <[email protected]>
+
+require 'puppet'
+require 'puppet/external/pson/common'
+
+class Puppet::Util::Runner
+
+ def initialize()
+ end
+
+ # If a groupfile exists in JSON format, expand any host expression
starting with ":"
+ # for example ":webservers" to the patterns listed under the group in the
file
+ # under that key. For instance, webservers may be web*.example.org and
www*.example.com
+ # If no groupfile exists, no problem, groups just won't work.
+ # FIXME: groups should be described in INI format?
+
+ def expand_groups(host_list)
+ groupfile = "#{Puppet[:confdir]}/hostgroups.conf"
+ begin
+ data = File.read(groupfile)
+ rescue Errno::ENOENT
+ return host_list
+ end
+ groups = PSON.parse(data)
+ host_list.inject([]) do |result,element|
+ if element =~ /^:/
+ result.concat(groups.fetch(element.sub(/^:/,''),[]))
+ else
+ result
+ end
+ end
+ end
+
+ # Return the host list converting any shell globs to full hostnames. For
+ # instance www*.example.com might match registered nodes www1 through 17.
+
+ def expand_hosts(host_list)
+ node_dir = "#{Puppet[:yamldir]}/node"
+ host_list.inject([]) do |result, element|
+ if (element =~ /\*|\?|\[\{/)
+ files = Dir.glob("#{node_dir}/#{element}.yaml")
+ hostnames = files.map { |filename| File.basename(filename,
".yaml") }
+ result.concat(hostnames)
+ else
+ result << element
+ end
+ end
+ end
+
+end
+
--
1.6.3.3
--
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.