Rundeck (Job scheduler and Runbook automation)

Installation
https://docs.rundeck.com/docs/administration/install/linux-deb.html#installing-rundeck
Switch to tab Community

sudo apt install -y curl
 
# OPTIONAL: install Java if not already available
sudo apt-get install -y openjdk-11-jre-headless
 
curl -L https://packages.rundeck.com/pagerduty/rundeck/gpgkey | sudo apt-key add -
 
cat <<EOF> /etc/apt/sources.list.d/rundeck.list
deb https://packages.rundeck.com/pagerduty/rundeck/any/ any main
deb-src https://packages.rundeck.com/pagerduty/rundeck/any/ any main
EOF
 
sudo apt-get update
sudo apt-get install -y rundeck
 
#sudo apt install -y sshpass

Configuration

ansible-playbook rundeck-ansible.example.com.yml -i your_inventory

---
hosts: rundeck-ansible.example.com
  vars:
    port_redirect:
      from: 4440
      to: 80
    install_ansible_plugin: true
  roles:
    - ansible
    - rundeck
>

Ansible role
https://github.com/panticz/ansible/tree/master/roles/rundeck
https://github.com/panticz/ansible/blob/master/rundeck.example.com.yml

Admin
http://localhost:4440/user/login;jsessionid=16lnsilhg9n6x38a090agwe8y

admin/admin

Configuration
https://docs.rundeck.com/docs/administration/configuration/configuration-file-reference.html

# override rundeck properties
/etc/rundeck/framework.properties
/etc/rundeck/rundeck-config.properties
/etc/rundeck/realm.properties
/etc/rundeck/rundeck-config.properties
 
# (global)
/etc/rundeck/framework.properties
 
# job database
/var/lib/rundeck/data/rundeckdb.mv.db
 
# hosts
/var/rundeck/projects/JOB_NAME/etc/resources.xml
 
# add user
echo "foo:bar,user,devops" >> /etc/rundeck/realm.properties
 
# acl
/var/rundeck/projects/<project_name>/acls/<project_name>.aclpolicy

Docker
https://docs.rundeck.com/docs/administration/configuration/docker.html
https://github.com/rundeck/docker-zoo/blob/master/cloud/docker-compose.yml
https://docs.rundeck.com/docs/administration/install/docker.html#open-source-rundeck

Configuration (project)

# configure nodes
/var/rundeck/projects/<project_name>/etc/resources.xml
 
# use native ssh agent to access host behind proxy / bastion
/var/rundeck/projects/<project_name>/etc/project.properties
plugin.script-exec.default.command=/usr/bin/ssh ${node.username}@${node.hostname} ${exec.command}
plugin.script-copy.default.command=/usr/bin/scp ${file-copy.file} ${node.username}@${node.hostname}\:${file-copy.destination}

Email notification
https://docs.rundeck.com/2.6.2/manual/jobs.html#execution-notification-url-token-expansion

# variables
${globals.environment} ${job.project} ${job.name} ${execution.status}

http://rundeck.org/docs/administration/email-settings.html

# /etc/rundeck/rundeck-config.properties
grails.mail.host=smtp.example.com
grails.mail.port=25
grails.mail.username=foo
grails.mail.password=bar
 
 
# restart service
service rundeckd restart
 
# ssh
mkdir /var/lib/rundeck/.ssh
chown rundeck:rundeck /var/lib/rundeck/.ssh
chmod 700 /var/lib/rundeck/.ssh
touch /var/lib/rundeck/.ssh/id_rsa
chown rundeck:rundeck /var/lib/rundeck/.ssh/id_rsa
chmod 600 /var/lib/rundeck/.ssh/id_rsa
 
# log
tail -f /var/log/rundeck/*.log

# Documentation
http://rundeck.org/
http://rundeck.org/docs/manual/getting-started.html
http://rundeck.org/2.3.2/administration/configuring-ssl.html

Plugins
https://www.rundeck.com/integrations/plugins
http://rundeck.org/plugins/ansible/2016/03/11/ansible-plugin.html
http://rundeck.org/plugins/2013/01/01/jenkins-rundeck.html
http://rundeck.org/plugins/2013/01/01/aws-ec2-nodes.html

scm
https://docs.rundeck.com/docs/developer/scm-plugins.html

/var/rundeck/projects/PROJECT_NAME/scm
/var/rundeck/projects/PROJECT_NAME/scm/scm-export.properties
/var/rundeck/projects/PROJECT_NAME/scm/cm-import.properties

Change default admin password
https://docs.rundeck.com/docs/administration/security/authenticating-users.html

USERNAME=admin
OLDPW="admin"
NEWPW="my_new_pass"
sed -i "/^${USERNAME}/ s|:${OLDPW}|:${NEWPW}|g" /home/rundeck/server/config/realm.properties
 
 
#RD_PASS=$(openssl rand -base64 16)
#echo ${RD_PASS}
#RD_PASS_MD5=$(java -cp /var/lib/rundeck/bootstrap/jetty-all-9.0.7.v20131107.jar org.eclipse.jetty.util.security.Password admin ${RD_PASS} 2>&1 | grep MD5)
#sed -i "s/^admin:admin/admin:MD5:${RD_PASS_MD5}/g" /etc/rundeck/realm.properties
java -jar /var/lib/rundeck/bootstrap/rundeck-*.war --encryptpwd Jetty
service rundeckd restart
 
# echo "framework.server.password = MD5:${RD_PASS_MD5}" >> /etc/rundeck/framework.properties
 
# Notify icinga
Local Command:
ssh monitoring.example.com '/usr/bin/printf "[%lu] SCHEDULE_FORCED_SVC_CHECK;%s;%s;%s\n" $(date +%s) ${node.name} APT $(date +%s) | tee -a /var/lib/icinga/rw/icinga.cmd'

# User authentification
http://rundeck.org/docs/administration/authenticating-users.html

Changelog
http://rundeck.org/docs/history/changelog.html

Rundeck jobs and scripts repository
https://github.com/panticz/rundeck

Job options
http://rundeck.org/2.0.0/manual/job-options.html

# use in bash
NODES=$(echo $RD_OPTION_NODES | sed 's/,/ /g')
 
# remote URL
https://docs.gitlab.com/ee/api/repository_files.html#get-file-from-repository
file:///tmp/foo.json
# dep # https://gitlab.example.com/foo/bar/raw/master/file.json?private_token=foo1234
 
https://gitlab.example.com/api/v4/projects/3/repository/files/${job.project}%2F${globals.environment}%2Foptions-hosts.json/raw?ref=master&private_token=${globals.private_token}

Call GitLab CI/CD pipeline
https://docs.gitlab.com/ee/ci/triggers/
https://git.example.com/everyware-customer-portal/customer-portal-conf/-/settings/ci_cd

export OS_ENV=dev
export TOKEN=12345678
 
# execute GitLab pipeline
curl -X POST \
  --silent \
  --fail \
  -F token=${TOKEN} \
  -F ref=${OS_ENV} \
  https://git.example.com/api/v4/projects/123/trigger/pipeline

Pipe command

echo ${option.RSA} | tee /tmp/debug.txt

Commands

# check file size
'[[ $(find /media/backup/db.mr/ -size +50M -name exp_$(date -I)_*.dmp.bz2 ) ]]'

API
https://docs.rundeck.com/docs/api/rundeck-api.html

GIT_SERVER=git.example.com
GIT_TOKEN=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
RUNDECK_JOB=287d18f7-6c95-40b7-8857-82d215c143e1
RUNDECK_TOKEN=yyyyyyyyyyyyyyyyyyyyyyyyy
ENVIRONMENT=stage
RUNDECK_SERVER=rundeck.${ENVIRONMENT}.example.com
RUNDECK_JOB_OPTIOONS=$(curl "https://${GIT_SERVER}/api/v4/projects/3/repository/files/OpenStack%2F${ENVIRONMENT}%2Foptions-hosts-all.json/raw?ref=master&private_token=${GIT_TOKEN}" | jq -r '.[] | select(.value != "control") .value' | paste -sd" ")
 
curl --location --request POST "http://${RUNDECK_SERVER}/api/40/job/${RUNDECK_JOB}/run" \
  --header "Accept: application/json" \
  --header "X-Rundeck-Auth-Token: ${RUNDECK_TOKEN}" \
  --header "Content-Type: application/json" \
  --data "{
    options: {
        nodes: ${RUNDECK_JOB_OPTIOONS}
    }
  }" | jq
 
# list tokens
curl -G -s -H "Accept: application/json" -H "X-RunDeck-Auth-Token:${RUNDECK_TOKEN}" "http://${RUNDECK_SERVER}/api/40/tokens" | jq
 
# get job definition
curl -G -s -H "Accept: application/json" -H "X-RunDeck-Auth-Token:${RUNDECK_TOKEN}" "http://${RUNDECK_SERVER}/api/40/job/${RUNDECK_JOB}" | jq
 
# get job info
curl -G -s -H "Accept: application/json" -H "X-RunDeck-Auth-Token:${RUNDECK_TOKEN}" "http://${RUNDECK_SERVER}/api/40/job/${RUNDECK_JOB}/info" | jq
 
# get all jobs
curl -G -s -H "Accept: application/json" -H "X-RunDeck-Auth-Token:${RUNDECK_TOKEN}" "http://${RUNDECK_SERVER}/api/40/project/OpenStack/jobs"  | jq
 
#  (call with parameter from curl)
curl -H "X-Rundeck-Auth-Token: ABCDEFGHIJKLMNOPRST1234567890" --data-urlencode "argString=-sku 'item1 item2 item3'" -X POST http://rundeck.example.com/api/25/job/26356713-8285-479e-860f-221559a64c23422/run
 
# fix Failed loading remote option values / Exception: java.lang.Exception: Unexpected content type received: text/plain; charset=utf-8 in Rundeck Allowed Values > Remote URL with currently:
# https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/23442
echo "framework.globals.environment=dev" >> /etc/rundeck/framework.properties

Output

# color
grep --color=always foo /path/to/file

Fix "Import Status: Not Tracked" issue

apt install -y git 
cd /var/rundeck/projects/DevOps/scm
git pull

Date option
https://stackoverflow.com/questions/44141399/pass-a-date-in-rundeck

Manage by teraform
https://registry.terraform.io/providers/rundeck/rundeck/latest/docs/resources/job

Health check
https://docs.rundeck.com/docs/administration/cluster/loadbalancer/health-check.html

http://rundeck.example.com/metrics/healthcheck

Renew GitLab openstack-ci private_token in rundeck

# generate new token for openstack-ci user
https://git.i.example.com/admin/users/cicd-user/impersonation_tokens
Token name: rundeck
read_repository
 
# get token (@workstation)
 PRIVATE_TOKEN=******
 
# Update private_token in rundeck
for OS_ENV in dev stage prod; do
    source ~/.rd/rundeck.${OS_ENV}.i.example.com.conf
    rd projects configure update -p OpenStack -- --project.globals.private_token=${PRIVATE_TOKEN}
done

job options
https://docs.rundeck.com/docs/administration/install/system-requirements.html
https://rundeck.org/docs/man5/resource-json.html
https://rundeck.org/docs/manual/defining-job-options.html
https://rundeck.org/2.8.2/administration/configuration-file-reference.html
https://rundeck.org/2.9.2/administration/gui-customization.html