Created
January 28, 2018 16:14
-
-
Save ripienaar/52e73db531cc22b434b8433ababd8df2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/opt/puppetlabs/puppet/bin/ruby | |
require "mcollective" | |
include MCollective::RPC | |
c = rpcclient("rpcutil") | |
# you'd read your file here or something to get the nodes list | |
nodes = c.discover | |
# your arguments to the agent goes in the hash here | |
req = c.new_request("ping", {}) | |
reqid = nil | |
# 10 is the batch size | |
nodes.in_groups_of(10) do |nodes| | |
message = MCollective::Message.new(req, nil, :agent => "rpcutil", | |
:type => :direct_request, | |
:collective => "mcollective", | |
:filter => MCollective::Util.empty_filter, | |
:options => c.options) | |
reqid ||= message.create_reqid | |
message.requestid = reqid | |
message.discovered_hosts = nodes.clone.compact | |
message.reply_to = "some.reply.target" | |
puts "Sending to %d nodes" % message.discovered_hosts.size | |
pp message.discovered_hosts | |
c.client.sendreq(message, nil) | |
# aadjust the sleep to your tastes | |
sleep 10 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment