Playbooks can be exported to .tgz files using the SOAR User Interface, one by one. However in an environment with many playbooks that can become a tedious task when exporting everything is needed.
This KB shows a way to automate that. It needs to be run in the SOAR command line and hence, it is only applicable for onPrem environments.
Two SOAR utilities are used here to achieve this.
1.- From command line, dbshell
2.- From REST API, the playbook export endpoint.
1.- Extract the id and name of all the PBs.
This command must be run in /opt/phantom/bin/. It will export only the latest version of each playbook, both active and non-active ones.
echo "select id ||','|| name as pb_id_name from playbook where disabled='f';" | /opt/phantom/bin/phenv python /opt/phantom/www/manage.py dbshell >> playbooks.txt
2.- Edit the file playbook.txt and remove the fist 2 lines and last one containing the header and rows count. It must contain only IDs and PB names.
pb_name_id
-----------------------------------------------------------------
1,AD_LDAP_Account_Locking
2,AD_LDAP_Account_Unlocking
...
...
(1553 rows)
3.- Using the SOAR REST API, use the PB export endpoint to extract all the PBs. Create a script that reads that file and makes curl commands to extract each PB.
https://docs.splunk.com/Documentation/SOARonprem/6.3.1/PlatformAPI/RESTPlaybook
As an example, this one does that and saves the PBs in the extractedPBs directory. It must run in the same directory where playbooks.txt file is.
Notice it needs the base url, and credentials:
#!/bin/bash
OUTPUT_DIR="./extractedPBs"# Check if the directory exists, if not, create it
if [ ! -d "$OUTPUT_DIR" ]; then
mkdir -p "$OUTPUT_DIR"
fi# Input file containing playbooks (id,name)
INPUT_FILE="playbooks.txt"# Base API URL
BASE_URL="https://1.2.3.4:8443/rest/playbook"# Credentials
USERNAME="admin"
PASSWORD="password"# Read the file line by line
while IFS=, read -r playbook_id playbook_name; do# Define the output file path in the specified directory
OUTPUT_FILE="${OUTPUT_DIR}/${playbook_name}.tgz"# Remove leading spaces
playbook_id=$(echo "$playbook_id" | sed 's/^ *//;s/ *$//')# Construct the curl command
CURL_CMD="curl -k -u \"$USERNAME:$PASSWORD\" --output \"$OUTPUT_FILE\" \"$BASE_URL/$playbook_id/export\""# Print the curl command
echo "Executing: $CURL_CMD"# Execute the curl command
eval $CURL_CMD# Print confirmation message
echo "Exported: $playbook_name (ID: $playbook_id) -> $OUTPUT_FILE"
done < "$INPUT_FILE"
4.- All the PBs are now in the ./extractedPBs directory.
| Revision | Publish Date | Comments |
|---|---|---|
1.0 |
29-Sep-2026
|
Initial Release |