4
# Nothing; we were just doing this just in case
10
$stderr.puts "Failed to load ruby LDAP library. LDAP functionality will not be available"
14
require 'puppet/application'
16
Puppet::Application.new(:puppetrun) do
18
should_not_parse_config
20
attr_accessor :hosts, :tags, :classes
23
option("--foreground","-f")
24
option("--debug","-d")
28
option("--host HOST") do |arg|
32
option("--tag TAG", "-t") do |arg|
36
option("--class CLASS", "-c") do |arg|
40
option("--no-fqdn", "-n") do |arg|
41
options[:fqdn] = false
44
option("--parallel PARALLEL", "-p") do |arg|
46
options[:parallel] = Integer(arg)
48
$stderr.puts "Could not convert %s to an integer" % arg.inspect
55
options[:test] ? :test : :main
59
puts "Skipping execution in test mode"
64
require 'puppet/network/client'
65
require 'puppet/util/ldap/connection'
71
# Now do the actual work
74
# If we don't have enough children in process and we still have hosts left to
75
# do, then do the next host.
76
if @children.length < options[:parallel] and ! todo.empty?
83
# Else, see if we can reap a process.
87
if host = @children[pid]
88
# Remove our host from the list of children, so the parallelization
94
print "%s finished with exit code %s\n" % [host, $?.exitstatus]
96
$stderr.puts "Could not find host for PID %s with status %s" %
100
# There are no children left, so just exit unless there are still
101
# children left to do.
102
next unless todo.empty?
108
puts "Failed: %s" % failures.join(", ")
116
def run_for_host(host)
118
out = %x{ping -c 1 #{host}}
120
$stderr.print "Could not contact %s\n" % host
124
client = Puppet::Network::Client.runner.new(
126
:Port => Puppet[:puppetport]
129
print "Triggering %s\n" % host
131
result = client.run(@tags, options[:ignoreschedules] || false, options[:foreground] || false)
133
puts detail.backtrace if Puppet[:trace]
134
$stderr.puts "Host %s failed: %s\n" % [host, detail]
139
when "success"; exit(0)
141
$stderr.puts "Host %s is already running" % host
144
$stderr.puts "Host %s returned unknown answer '%s'" % [host, result]
150
[:INT, :TERM].each do |signal|
152
$stderr.puts "Cancelling"
156
options[:parallel] = 1
157
options[:verbose] = true
158
options[:fqdn] = true
159
options[:ignoreschedules] = false
160
options[:foreground] = false
169
Puppet::Util::Log.level = :debug
171
Puppet::Util::Log.level = :info
174
# Now parse the config
177
if Puppet[:node_terminus] == "ldap" and (options[:all] or @classes)
179
@hosts = Puppet::Node.search("whatever").collect { |node| node.name }
180
puts "all: %s" % @hosts.join(", ")
183
@classes.each do |klass|
184
list = Puppet::Node.search("whatever", :class => klass).collect { |node| node.name }
185
puts "%s: %s" % [klass, list.join(", ")]
190
elsif ! @classes.empty?
191
$stderr.puts "You must be using LDAP to specify host classes"
198
@tags = @tags.join(",")
203
# If we get a signal, then kill all of our children and get out.
204
[:INT, :TERM].each do |signal|
206
Puppet.notice "Caught #{signal}; shutting down"
207
@children.each do |pid, host|
208
Process.kill("INT", pid)