How can Rundeck pass a list of machines to the script?

quat picture quat · Jun 18, 2015 · Viewed 7.4k times · Source

I am currently exploring Runddeck to manage several 100 VMs at the time. Rundeck is a very useful tool to run scripts/ commands on multiple machines at the time (each script is passed to the remote machine and then executed locally). However I wonder if there is a way of implementing the following system administation scenario.

Rundeck job requirments (Example: Observium)

  1. "Dispatch to Nodes" option selected but only one target machine selected (Observium machine).
  2. Despite of running the job on only one machine, it would be great if Rundeck allows to select multiple machines, which the script requires. Note, the script is not supposed to be run on all nodes, it's only supposed to be run on a single remote machine but the script requires the list of machines. [How can this be done?]
  3. The script gets access to the list of machines as parameter. [How can this be done?]
  4. If the above is in place, the script then runs on only one machine and iterates through the list of machines ==> For example, it runs /opt/observium/add_device.php v2c @node.name@ ${varSNMPCommunity}

I don't have enough reputation to include images in this post. Please use the link below to see the flow diagram.

https://www.dropbox.com/s/2zt4r9trulpsaqx/RundeckObservium.png?dl=0

Answer

SaxDaddy picture SaxDaddy · Jun 21, 2015

Rather than have the script run on one node to get a list of machines, try using a node filter to see if you can have RunDeck determine the target nodes from a tag. This will depend on how your project is configured to acquire resources.

For example, if you're using tags then you may want to have a tag that meets your condition. Say you want to find machines that match a tag you created called RebootPending. You can use that as the job's node filter to send a reboot command to those hosts.

Another possible option might be to have your step 2 script output a JSON formatted file to a web server. You can then configure your RD job with an Option that reads this remote URL (a list of host, perhaps) and then take an action based on that list. The job option and node filter can be configured thusly:

Option Name: inputFilter
Description: Used for targeting nodes
Default Value: (empty)
Input Type: [X]Plain text [ ]Secure [ ]Secure Remote Authentication
Allowed Values: [ ]List  [X]Remote URL

Node Filter: tags:${option:inputFilter}

By using these setup, you can have the remote web page (e.g., your script's output) determine the target nodes. Note that the RunDeck JSON format is specific and doesn't report read errors well. Pay close attention to the Rundeck User Guide - Option model provider

If this is not a viable approach, you may need to consider using a different tool such as Jenkins.