Skip to content

Commit

Permalink
Merge pull request #5 from panubo/add_config_exprorter
Browse files Browse the repository at this point in the history
Add export_jobs.sh to allow exporting all currently loaded jobs
  • Loading branch information
macropin authored Mar 22, 2023
2 parents 9dcff9f + a2d91b4 commit 515c131
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,11 @@
mode: "0700"
owner: root
group: root

- name: Write export_jobs.sh
template:
dest: "/export_jobs.sh"
src: "templates/export_jobs.sh.j2"
mode: "0700"
owner: root
group: root
2 changes: 1 addition & 1 deletion ansible-bootstrap/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
- rundeck_tokens: []

tasks:
- include_tasks: configure_script.yml
- include_tasks: configure_scripts.yml
- include_tasks: configure.yml
- include_tasks: permissions.yml
- include_tasks: ssh.yml
Expand Down
69 changes: 69 additions & 0 deletions ansible-bootstrap/templates/export_jobs.sh.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/usr/bin/env bash
#
# Export all currently loaded Rundeck jobs
#
# Path structure:
# /projects/<project_name>/<job_name>.yaml
#
# Using:
# - https://rundeck.github.io/rundeck-cli/commands/

set -e

export RD_TOKEN="{{ rundeck_token_configuresh }}"
CONFIG_DIR="${CONFIG_DIR:-/config}"

# wait_http URL [TIMEOUT] [HTTP TIMEOUT]
wait_http() {
# Wait for http service to be available
command -v curl >/dev/null 2>&1 || { error "This function requires curl to be installed."; return 1; }
local url="${1:-'http://localhost'}"
local timeout="${2:-30}"
local http_timeout="${3:-2}"
echo -n "Connecting to HTTP at ${url}"
for (( i=0;; i++ )); do
if [[ "${i}" -eq "${timeout}" ]]; then
echo " timeout!"
return 99
fi
sleep 1
(curl --max-time "${http_timeout}" "${url}") &>/dev/null && break
echo -n "."
done
echo " connected."
exec 3>&-
exec 3<&-
}

wait_http "${RD_URL}" 300

get_installed_projects() {
# remove last blank line
echo "$(rd projects list --outformat "%name")"
}

get_installed_jobs() {
# remove last blank line
echo "$(rd jobs list -p ${1} --format yaml --outformat "%name")"
}

write_job() {
# write out the job to the config dir
rd jobs list -p ${1} --format yaml -J ${2} -f ${CONFIG_DIR}/projects/${1}/${2}.yaml
}

echo ">> Running $(basename "$0")"

if [ -d "${CONFIG_DIR}/projects" ]; then

for PROJECT in $(get_installed_projects); do
echo "> $PROJECT"
for JOB in $(get_installed_jobs "${PROJECT}"); do
echo ">> $JOB"
write_job ${PROJECT} ${JOB}
done
done

fi

echo ">> Finished $(basename "$0")"

0 comments on commit 515c131

Please sign in to comment.