Note: Please go to docs.rightscale.com to access the current RightScale documentation set. Also, feel free to Chat with us!
Home > Guides > RightScale API 1.5 > Examples > Server Array > Run an Executable on All Server Array Instances

Run an Executable on All Server Array Instances

Runs a Rightscript or Chef recipe on all instances in a Server Array

icon-curl_api-v1.png    icon-right_api_client-v1.png

 

Table of Contents

 

Curl

Basic Example

Note:

  • This example runs an executable on multiple instances within a Server Array only
  • Cloud ID, ServerArray ID and Rightscript ID must be gathered prior to running the example bash script below. These IDs can be located in the Rightscale dashboard or via other API 1.5 calls.
  • This is similar to Run Executable, but instead of running on a single active running server, this script updates multiple active servers in a Server Array
  • When specifying RightScale input(s), you must declare both the name and value.
  • By default, the executable will be run on every array instance in a server array unless filters are used

 

#!/bin/bash
cloud_id=3
array_id=224754003
script_id=500272003

curl -v -X POST -H 'X-API-VERSION:1.5' -b myCookie \
-d "filter[]=parent_href==/api/server_arrays/$array_id" \
-d "right_script_href=/api/right_scripts/$script_id" \
-d "inputs[][name]=INPUT1" \
-d "inputs[][value]=text:InputValue" \
https://us-3.rightscale.com/api/clouds/$cloud_id/instances/multi_run_executable

 

The same script can also be ran using the Server Arrays resource and URL along with omitting the parent_href filter, like so:

#!/bin/bash
cloud_id=3
array_id=224754003
script_id=500272003

curl -v -X POST -H 'X-API-VERSION:1.5' -b myCookie \
-d "right_script_href=/api/right_scripts/$script_id" \
-d "inputs[][name]=INPUT1" \
-d "inputs[][value]=text:InputValue" \
https://us-3.rightscale.com/api/server_arrays/$array_id/multi_run_executable

Sample Output

Note:

  • Output below may have omitted sections for brevity.
  • Output below also includes command issued as first line.
  • <Location> header returns an HREF to the task of the script run, which can be monitored with a subsequent API call. See the ResourceTasks section of the API 1.5 reference for more information.
curl -v -X POST -H 'X-API-VERSION:1.5' -b myCookie -d "filter[]=parent_href==/api/server_arrays/224754003" -d "right_script_href=/api/right_scripts/500272003" -d "inputs[][name]=INPUT1" -d "inputs[][value]=text:InputValue" https://us-3.rightscale.com/api/clouds/3/instances/multi_run_executable
...
*   Trying 107.20.150.177...
* Connected to us-3.rightscale.com (107.20.150.177) port 443 (#0)
...
< HTTP/1.1 202 Accepted
...
< Location: /api/clouds/3/instances/5B3O71B8JOU7H/live/tasks/ae-249234120003

Right_api_client

Basic Example

Note:

  • This example runs an executable on all instances within a Server Array only
  • This is similar to Run Executable, but instead of running on a single active running server, this script updates multiple active servers, which is beneficial for running a script or recipe on server arrays.
  • By default, the executable will be run on every array instance in a server array unless filters are used
  • When specifying RightScale input(s), you must declare both the name and value.
  • To run this script, you must know your Server Array ID as well as the Chef recipe name or Rightscript HREF, which are both obtainable from the Rightscale dashboard or using other API 1.5 calls.
  • ## Example that runs a Rightscript on all array instances with a single input
    
    @client.server_arrays(:id => 224754003).multi_run_executable("right_script_href=/api/right_scripts/500272003" + "&inputs[][name]=INPUT1&inputs[][value]=TestValue")
    
    ## Example that runs a Chef recipe on all array instances with no inputs defined (pre-defined on array/instance level)
    ## If inputs are needed, follow same syntax as script example above
    
    @client.server_arrays(:id => 224754003).multi_run_executable("recipe_name=sys_firewall::setup_rule")
    
    
    

Sample Output

Note:

  • Sample output below comes from interactive Ruby shell (IRB) and uses sample script and server IDs. Your script HREF and server ID would be different in your own output.
## IRB Output from Rightscript run with one input

irb(main):059:0> @client.server_arrays(:id => 224754003).multi_run_executable("right_script_href=/api/right_scripts/500272003" + "&inputs[][name]=INPUT1&inputs[][value]=TestValue")
=> #<RightApi::Resource resource_type="task">

## IRB Output from Chef recipe run

irb(main):063:0> @client.server_arrays(:id => 224754003).multi_run_executable("recipe_name=sys_firewall::setup_rule")
=> #<RightApi::Resource resource_type="task">

 

Navigating to any instance in the array, then clicking on the Audit Entries tab will also give you status of the script/recipe run from the right_api_client command, as seen here:

 

screen-right_api_client_multi_run_output-v1.png

You must to post a comment.
Last modified
10:54, 21 Nov 2013

Tags

This page has no custom tags.

Classifications

This page has no classifications.

Announcements

None


© 2006-2014 RightScale, Inc. All rights reserved.
RightScale is a registered trademark of RightScale, Inc. All other products and services may be trademarks or servicemarks of their respective owners.