Call APIs from Rundeck
Call APIs from Rundeck
Modern applications use the HTTP protocol to communicate with each other and send or obtain information from any web service using HTTP methods like GET, POST, or PUT. For example, to obtain a valid user ID from a web service to use it later in another process/application.
To make those HTTP calls we can use an inline-script] with a cURL command inside, curl is used in scripts or commands to transfer data and it’s available for any operating system. But this implies maintaining a lot of code inside a Rundeck workflow.
Rundeck’s Job Steps offer a more user-friendly way to make these calls. For HTTP calls, use the HTTP Workflow Step Plugin in Rundeck. This plugin will send HTTP calls to any web service or HTTP endpoint. The returned data can then be used in subsequent steps. (Check out our Passing Variables guide).
If you are using our Enterprise version the plugin is already bundled with your installation. Skip straight to the exercises.
Community Version Prerequisite
The HTTP Workflows Step plugin isn’t bundled with the Rundeck Community version (it is included with Runbook Automation). For Rundeck Community, follow these steps to install it.
- Go to the System Menu (Gear Icon in upper right) > Plugins > Upload Plugin.
- Copy the plugin file location from the repository (Latest link as of last update is below)
https://github.com/rundeck-plugins/http-step/releases/download/1.0.12/http-step-1.0.12.jar
Upload Plugin - Paste it on the Plugin URL textbox, and click on the Install button.
An alternative method to install the plugin is to download the .jar file directly from the repository and put it on the
libext
directory (at/var/lib/rundeck/libext` on RPM / DEB based installations or
$RDECK_BASE/libext` directory on WAR based installations). Just copy the the .jar to the folder, no restart is needed.
Exercise
Warning
For this exercise we will use the site httpbin.org test website, httpbin.org is a simple HTTP request and response service written in python by Ken Reitz. This is not a site owned or run by PagerDuty. Note: Don't send any sensitive data. This site is simply used as a test. If you would like to run your own their site has more information about using their Docker Images.
Other Parameters
Other parameters available:
- Request Timeout (How long to wait for a request to complete before failing).
- Validate SSL Certificates (true or false, validate that SSL certificates are trusted, match the hostname, etc.)
- Authentication section. If the HTTP service uses Basic / OAuth2 authentication. On Basic Auth it’s possible to define the user and password from the Rundeck Key Storage. On OAuth 2.0 add the OAuth Token URL and OAuth Validate URL.
- Validate Response can check the HTTP response code that is returned and fail the step if it is not the expected value. (typically looking for 200)
- Proxy Settings section, if the HTTP service is behind a proxy server, you can define the Proxy IP address and port.
Additional Information
- If you need to use variables in the HTTP Request Steps Headers or Body sections use the format
${data.variable-name}
. For more information about using variables check out Passing Data Between Steps - Link to Example Job built using the steps above. Download the YAML and use it in your Rundeck.
- Official plugin description from the plugin's GitHub repository.
- Documentation on different HTTP methods.