Skip to content
This repository has been archived by the owner on Nov 28, 2018. It is now read-only.

Heya #10

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Heya #10

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions agent/puppetd/agent/puppetd.ddl
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,20 @@ action "disable", :description => "Disables the Puppetd" do
end

action "runonce", :description => "Initiates a single Puppet run" do
#input :forcerun,
# :prompt => "Force puppet run",
# :description => "Should the puppet run happen immediately",
# :type => :string,
# :validation => '^.+$',
# :optional => true,
# :maxlength => 5
input :forcerun,
:prompt => "Force puppet run",
:description => "Should the puppet run happen immediately",
:type => :boolean,
:optional => true

input :env,
:prompt => "Environment",
:description => "Environment agent should use, if any",
:type => :string,
:validation => '^[^\d][a-zA-Z_\d]+$',
:optional => true,
:maxlength => 100

output :output,
:description => "Output from puppetd",
:display_as => "Output"
Expand Down
4 changes: 4 additions & 0 deletions agent/puppetd/agent/puppetd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ def runonce
end
end

if request[:env]
cmd << "--environment" << request[:env]
end

cmd = cmd.join(" ")

if respond_to?(:run)
Expand Down
23 changes: 21 additions & 2 deletions agent/puppetd/application/puppetd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ class MCollective::Application::Puppetd<MCollective::Application
:arguments => ["--force", "-f"],
:type => :bool

option :env,
:description => "Environment to pass to puppet when invoking runonce or runall",
:arguments => ["--environment", "-e [ENV]"]

def post_option_parser(configuration)
if ARGV.length >= 1
configuration[:command] = ARGV.shift
Expand All @@ -15,11 +19,25 @@ def post_option_parser(configuration)
unless configuration[:command].match(/^(enable|disable|runonce|runall|status|summary|count)$/)
raise "Command has to be enable, disable, runonce, runonce, runall, status, summary or count"
end

#I would think the :bool type above would take care of this
unless configuration[:force]
configuration[:force] = false
end
else
raise "Please specify a command"
end
end

def get_opts
opts = {:forcerun => configuration[:command] == "runall" ? true : configuration[:force] }
if configuration[:env]
opts[:env] = configuration[:env]
log("Passing explicit environment #{opts[:env]}")
end
return opts
end

# Prints a log statement with a time
def log(msg)
puts("#{Time.now}> #{msg}")
Expand Down Expand Up @@ -69,7 +87,7 @@ def main
hosts.each do |host|
running = waitfor(configuration[:concurrency], mc)
log("Running #{host}, concurrency is #{running}")
result = mc.custom_request("runonce", {:forcerun => true}, host, {"identity" => host})
result = mc.custom_request("runonce", get_opts, host, {"identity" => host})

if result.is_a?(Array)
log("#{host} schedule status: #{result[0][:statusmsg]}")
Expand All @@ -85,7 +103,7 @@ def main
end

when "runonce"
printrpc mc.runonce(:forcerun => configuration[:force])
printrpc mc.runonce(get_opts)

when "status"
mc.send(configuration[:command]).each do |node|
Expand Down Expand Up @@ -127,3 +145,4 @@ def main
printrpcstats
end
end
# vi:tabstop=4:expandtab:ai:filetype=ruby
22 changes: 19 additions & 3 deletions agent/puppetd/sbin/mc-puppetd
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ options = rpcoptions do |parser, options|
parser.on("--force", "-f", "Force the puppet run to happen immediately without splay") do
@force = true
end

parser.on("--environment", "-e ENVIRONMENT", "Environment option to invoke runonce or runall") do |v|
@env = v
end
end

puppetd = rpcclient("puppetd", :options => options)
Expand Down Expand Up @@ -62,6 +66,18 @@ def waitfor(concurrency, client)
end
end

def get_opts(command)
#Always force for runall
opts = {:forcerun => command == "runall" ? true : @force}

if [email protected]?
log("Passing explicit environment #{@env}")
opts[:env] = @env
end

return opts
end

if command == "status"
puppetd.send(command).each do |node|
node[:statuscode] == 0 ? msg = node[:data][:output] : msg = node[:statusmsg]
Expand Down Expand Up @@ -96,6 +112,7 @@ elsif command == "count"
elsif command == "runall"
if ARGV.length == 1
concurrency = ARGV.shift.to_i
opts = get_opts(command)

if concurrency > 0
log("Running all machines with a concurrency of #{concurrency}")
Expand All @@ -116,7 +133,7 @@ elsif command == "runall"

log("Running #{host}, concurrency is #{running}")

result = puppetd.custom_request("runonce", {:forcerun => true}, host, {"identity" => host})
result = puppetd.custom_request("runonce", opts, host, {"identity" => host})

if result.is_a?(Array)
log("#{host} schedule status: #{result[0][:statusmsg]}")
Expand All @@ -140,10 +157,9 @@ elsif command == "summary"
printrpcstats

elsif command == "runonce"
printrpc puppetd.runonce(:forcerun => @force)
printrpc puppetd.runonce(get_opts(command))

printrpcstats

else
printrpc puppetd.send(command)

Expand Down