Rundeck CLI

Install
https://rundeck.github.io/rundeck-cli/
https://github.com/rundeck/rundeck-cli/releases

sudo apt-get install -y default-jre-headless
 
wget -q https://github.com/rundeck/rundeck-cli/releases/download/v2.0.0/rundeck-cli_2.0.0-1_all.deb
sudo dpkg -i rundeck-cli_*_all.deb
 
# sudo apt-get install rundeck-cli

Configuration
https://rundeck.github.io/rundeck-cli/configuration/

# ~/.rd/rundeck-dev.conf
export RD_URL=http://rundeck.dev.example.com:80
export RD_USER=admin
export RD_PASSWORD=admin
 
# load configuration
source ~/.rd/rundeck-dev.conf

Commands
https://rundeck.github.io/rundeck-cli/commands/

rd projects create -p ops
rd projects configure set -p ops --file ~/project.properties
rd keys create --type privateKey --path keys/lib/rundeck/.ssh/github_rsa --file ~/github_rsa
rd projects scm setup -p ops --integration import --type git-import --file ~/scm-import.json
rd projects scm perform -p ops -i import --action initialize-tracking -f useFilePattern="true" filePattern=".*\\.yaml"
rd projects scm perform -i import -p ops --action import-all
rd projects scm perform -i import -p ops --action import-all --item "ops/my-job-file.yaml"

Create / configure Project properties
https://docs.rundeck.com/docs/administration/configuration/config-file-reference.html#project-properties

rd projects create -p project1
 
rd projects configure get -p project1
 
# import porject settings from configuration file
rd projects configure set -p project1 --file ~/project.properties

Nodes

# Configure node from remote URL
rd projects configure update -p project1 -- \
  --resources.source.1.type=url \
  --resources.source.1.config.url='https://git.i.example.com/api/v4/projects/3/repository/files/project1%2Fdev%2Fnodes.json/raw?ref=master&private_token=1234567890' \
  --resources.source.1.config.timeout=10 \
  --resources.source.1.config.cache=false 
 
# from file
rd projects configure set -p project1 --
--resources.source.1.config.file="/home/rundeck/iidas/resources.xml" \
--resources.source.1.config.generateFileAutomatically=true \
--resources.source.1.config.includeServerNode=true \
--resources.source.1.type=file

Configure SSH keys

# Optional: generate rundeck SSH key
# ssh-keygen -m PEM -b 4096  -C "rundeck@rundeck.dev.example.com"
 
rd keys create --type privateKey --path id_rsa --file ~/backup/rundeck.dev.i.example.com/ssh/id_rsa
rd keys create --type privateKey --path keys/project/project1/id_rsa --file ~/backup/rundeck.dev.i.example.com/ssh/id_rsa
 
rd projects configure update -p project1 -- \
  --service.FileCopier.default.provider=ssh-copier \
  --service.NodeExecutor.default.provider=ssh-exec \
  --project.plugin.NodeExecutor.ssh-exec.authentication=privatekey \
  --project.plugin.FileCopier.ssh-copier.authentication=privatekey \
  --project.plugin.NodeExecutor.ssh-exec.ssh_key_storage_path=keys/id_rsa \
  --project.plugin.FileCopier.ssh-copier.ssh_key_storage_path=keys/id_rsa

SCM

# Export SCM import configuration
rd projects scm config --project project1 --integration import --file /tmp/project1-scm-import.out
cat /tmp/project1-scm-import.out | jq > project1-scm-import.json
 
# Export SCM export configuration
rd projects scm config --project project1 --integration export --file /tmp/project1-scm-export.out
cat /tmp/project1-scm-export.out | jq > project1-scm-export.json
 
# Import SCM import configuration
rd projects scm setup -p project1 --integration import --type git-import --file project1-scm-import.json
#rd projects scm perform -p project1 -i import --action initialize-tracking -f useFilePattern="true" # filePattern=".*\\.yaml"
#rd projects scm perform -p project1 -i import --action import-all --item "ops/my-job-file.yaml"
rd projects scm perform -p project1 -i import --action import-all --allitems
 
# Import SCM export configuration
rd projects scm setup -p project1 --integration export --type git-export --file project1-scm-export.json

Tokens

# create token
rd tokens create --user admin --roles admin,user
rd tokens create --user admin --roles all #--verbose
 
# list
rd tokens list --user admin

Configure mailserver

rd projects configure update -p OpenStack -- \
  --resources.grails.mail.host=smtp.example.com \
  --resources.grails.serverURL=http://rundeck.${OS_ENV}.example.com

Renew GitLab user private_token in rundeck

# generate new token for openstack-ci user
https://git.i.example.com/admin/users/my-cicd-user/impersonation_tokens
 
# get token
PRIVATE_TOKEN=******
 
# Update private_token in rundeck
source ~/.rd/rundeck.${ENV}.i.example.com
rd projects configure update -p OpenStack -- --project.globals.private_token=${PRIVATE_TOKEN}

Links
https://github.com/rundeck/rundeck-cli/issues/62