#!/bin/bash
set -euo pipefail
#==============================================================#
# File      :   svg
# Desc      :   Generate playbook svg @ files/svg
# Ctime     :   2021-04-20
# Mtime     :   2022-12-03
# Path      :   bin/svg
# Deps      :   ansible-playbook-grapher, graphviz
# License   :   Apache-2.0 @ https://pigsty.io/docs/about/license/
# Copyright :   2018-2026  Ruohang Feng / Vonng (rh@vonng.com)
#==============================================================#
PROG_NAME="$(basename $0)"
PROG_DIR="$(cd $(dirname $0) && pwd)"


# pigsty home directory
PIGSTY_HOME="$(cd $(dirname ${PROG_DIR}) && pwd)"
SVG_DIR=${PIGSTY_HOME}/temp/docs/_media/playbook
cd ${PIGSTY_HOME}
mkdir -p ${SVG_DIR}


# 4 major construct playbooks
ansible-playbook-grapher deploy.yml  -o ${SVG_DIR}/deploy
ansible-playbook-grapher node.yml    -o ${SVG_DIR}/node
ansible-playbook-grapher infra.yml   -o ${SVG_DIR}/infra
ansible-playbook-grapher pgsql.yml   -o ${SVG_DIR}/pgsql
ansible-playbook-grapher redis.yml   -o ${SVG_DIR}/redis

# 4 major destruct playbooks
ansible-playbook-grapher --include-role-tasks infra-rm.yml -o ${SVG_DIR}/infra-rm
ansible-playbook-grapher --include-role-tasks nodes-rm.yml -o ${SVG_DIR}/nodes-rm
ansible-playbook-grapher --include-role-tasks pgsql-rm.yml -o ${SVG_DIR}/pgsql-rm
ansible-playbook-grapher --include-role-tasks redis-rm.yml -o ${SVG_DIR}/redis-rm

# 7 auxiliary playbooks
ansible-playbook-grapher pgsql-user.yml        --include-role-tasks -o ${SVG_DIR}/pgsql-user
ansible-playbook-grapher pgsql-db.yml          --include-role-tasks -o ${SVG_DIR}/pgsql-db
ansible-playbook-grapher pgsql-rm.yml          --include-role-tasks -o ${SVG_DIR}/pgsql-rm
#ansible-playbook-grapher pgsql-monly.yml      --include-role-tasks -o ${SVG_DIR}/pgsql-monly
#ansible-playbook-grapher pgsql-migration.yml  --include-role-tasks -o ${SVG_DIR}/pgsql-migration
