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 > Instances > Multi-Run Executable

Multi-Run Executable

Runs a RightScript or Chef Recipe on multiple active RightScale Servers.

icon_curl_v1.png    icon-right_api_client-v1.png

Table of Contents

Curl

Prerequisite:  Example assumes you have previously authenticated, and your valid session cookie is in 'mycookie'.

Basic Example

Note:

  • 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.
  • When specifying RightScale input(s), you must declare both the name and value.
  • The example below runs a recipe. 
#!/bin/sh -e
cloud_id="3"
curl -i -H X_API_Version:1.5 -b mycookie -X POST \
 -d recipe_name="sys_firewall::setup_rule" \
 -d inputs[][name]="sys_firewall/rule/enable" \
 -d inputs[][value]="text:enable" \
 -d inputs[][name]="sys_firewall/rule/ip_address" \
 -d inputs[][value]="text:any" \
 -d inputs[][name]="sys_firewall/rule/port" \
 -d inputs[][value]="text:22"\
 -d inputs[][name]="sys_firewall/rule" \
 -d inputs[][value]="text:tcp" \
https://my.rightscale.com/api/clouds/$cloud_id/instances/multi_run_executable.xml

Sample Output

HTTP/1.1 202 Accepted
Server: nginx/1.0.14
Date: Fri, 15 Mar 2013 18:02:56 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Status: 202 Accepted
Location: /api/clouds/3/instances/6A5PGI1SG74RN/live/tasks/ae-160056990003
X-Runtime: 2862
X-Request-Uuid: bf9159a6497440f3be3ec6c7e0f16a3e
Set-Cookie: 
Cache-Control: no-cache

Right_api_client

Basic Example

Note:

  • This example runs an executable on multiple instances, even if they are outside of a Server Array
  • This is similar to Run Executable, but instead of running on a single active running server, this script updates multiple active servers.
  • By default, the executable will be run on every instance specified in the cloud unless additional filters are given.
  • When specifying RightScale input(s), you must declare both the name and value.
  • To run this script, you must know your Cloud 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 cloud instances in a single cloud with a single input
    ## Also stores the returned task object as 'task,' which in turn can be used to check summary/status
    
    task = @client.clouds.index(:id => 3).show.instances.multi_run_executable(:right_script_href => '/api/right_scripts/500272003', :inputs => {'INPUT1' => "text:TestValue1"})
    
    ## Same command, only runs a Chef recipe by name instead of a Rightscript by HREF
    
    task = @client.clouds.index(:id => 3).show.instances.multi_run_executable(:recipe_name => 'sys_firewall::setup_rule', :inputs => {'INPUT1' => "text:TestValue1"})

Advanced Examples

Filtering for Specific Instances

This example is similar to the above example, however many people may not wish to run the recipe or Rightscript on every instance in a single cloud. The below example allows you to run the recipe or Rightscript on specific instances defined with filters, such as:

  • In a specific cloud
  • Within a specific Deployment
  • Contains a specific string in it's Nickname
## Uses deployment_href and name filters to specify only instances within a Deployment that contain a specific string in their name

@client.clouds.index(:id => 3).show.instances.multi_run_executable(:filter => ['deployment_href==/api/deployments/434815003','name==#2'], :right_script_href => '/api/right_scripts/500272003', :inputs => {'INPUT1' => "text:TestValue1"})

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.
  • Sample output includes commands issued from example above.
## IRB Output from Rightscript run with one input. 

irb(main):025:0> task = @client.clouds.index(:id => 3).show.instances.multi_run_executable(:right_script_href => '/api/right_scripts/500272003', :inputs => {'INPUT1' => "text:TestValue1"})
=> #<RightApi::Resource resource_type="task">

## IRB Output from Chef recipe run

irb(main):017:0> task = @client.clouds.index(:id => 3).show.instances.multi_run_executable(:recipe_name => 'sys_firewall::setup_rule', :inputs => {'INPUT1' => "text:TestValue1"})
=> {"links"=>[], "summary"=>"0%: Multi run executable action for instances through API.", "actions"=>[]}

## Follows up on the task status

irb(main):029:0> task.show.summary
=> "completed: Multi run executable action for instances through API."

 

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

 

screen-right_api_client_multi_run_output-v1.png

 

 

You must to post a comment.
Last modified
11:34, 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.