Skip to content

Instantly share code, notes, and snippets.

@ripienaar
Created January 28, 2018 16:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ripienaar/52e73db531cc22b434b8433ababd8df2 to your computer and use it in GitHub Desktop.
Save ripienaar/52e73db531cc22b434b8433ababd8df2 to your computer and use it in GitHub Desktop.
#!/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