Monday 30 March 2015

Rundeck API small script

This is a demo script for using Rundeck and its API.

Rundeck API is a cumulative work that has api numbers from 1 to 12 up to now.
It will allow you to list and execute rundeck jobs remotely and also to monitor them remotely.
This will be very useful also for rundeck scripts that would call another remote rundeck jobs, this can be a good work around for remote execution when SSH is not allowed for security reasons.
Also would server to put your entire Ops jobs and infra under control using a simple web application.

The applications for this is limitless.
link this with my earlier post for nodeJS shell execution and u will have a lot of options to automation.

Below is a small example:

PROJECTS=`curl -H "Accept: application/json" http://beren:4440/api/1/projects?authtoken=It4kb1tIgw8gBpKI3rQhscKTp0OVYSNo |tr "}" "\n"|tr "," "\n"|grep name|cut -d":" -f2 |tr -d "\""`

#echo $PROJECTS
for proj in $PROJECTS
do
        #get all Jobs in all projects:
        echo "Project: $proj"
        curl "http://beren:4440/api/1/jobs?authtoken=It4kb1tIgw8gBpKI3rQhscKTp0OVYSNo&project=${proj}" #egrep "\<name>|\<job id="
done


To Run your job directly use a URL similar to below:

curl "http://beren:4440/api/1/job/61894b63-d687-4a39-a583-e0eba070339f/run?authtoken=It4kb1tIgw8gBpKI3rQhscKTp0OVYSNo"

1 comment:

  1. Thanks a lot. Great post. You saved my day!!!

    ReplyDelete