Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass argumets to RunDeck Run API

Tags:

rundeck

I want to run a rundeck job using the run API. Would like to pass few parameters as well to the runDeck job during the run time.

Do I need to configure the job to accept parameters? How to pass parameters to run API?

Thanks in advance

Regards SJ

like image 335
SAJ Avatar asked Dec 18 '14 06:12

SAJ


People also ask

How do I use rundeck API?

To obtain an API Token, you must first log in to the Rundeck GUI using a user account. Click on your username in the header of the page, and you will be shown your User Profile page. From this page you can manage your API Tokens.

How do I create API token in rundeck?

Generate API Token You can create a new API Token by clicking the "+" button. You can provide a name to easily identify this token. If you have admin authorization, you can specify the User, and list of Roles to store in the Token.


2 Answers

Option 1: In absence of tokens, first login to get cookie

curl \
  -D - \
  -X POST \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -H "Cache-Control: no-cache" \
  -d "j_username=${RD_USER}&j_password=${RD_PASSWORD}" \
  --cookie-jar rd_cookie \
  "${RD_URL}/j_security_check"

Then, use the cookie received from successful login for subsequent transactions

curl \
  -D - \
  -X "POST" \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -d "{\"argString\":\"-arg1 val1 -arg2 val2 -arg3 val-3 -arg4 val4 \"}" \
  --cookie "@rd_cookie" \
  "${RD_URL}/api/16/job/${RD_JOB_ID}/executions"

Option 2: With a token, it's simpler

curl \
  -D - \
  -X "POST" -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -H "X-Rundeck-Auth-Token: ${RD_TOKEN}" \
  -d "{\"argString\":\"-arg1 val1 -arg2 val2 -arg3 val-3 -arg4 val4 \"}" \
  "${RD_URL}/api/16/job/${RD_JOB_ID}/executions"
like image 129
swapz83 Avatar answered Oct 16 '22 19:10

swapz83


The API documentation for Rundeck describes how to run a job:

  • http://rundeck.org/docs/api/#running-a-job

Yes you need to create a parametrized job and pass in arguments as part of the API call. This could be considered a security measure only expected parameters can be accepted.

like image 44
Mark O'Connor Avatar answered Oct 16 '22 19:10

Mark O'Connor