Compare commits
3
Commits
29d4f33a46
...
673e318824
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
673e318824
|
||
|
|
71261e4017
|
||
|
|
9fb64cef30
|
@@ -188,7 +188,7 @@ Depending on what you are trying to do with a new playbook, the best approach ma
|
|||||||
|
|
||||||
### CLI Tool
|
### CLI Tool
|
||||||
|
|
||||||
As an alternative, you can use the `skato-ansible` shell script in `$ANSIBLE_PROJECT_ROOT` as an abstraction of the `ansible-playbook` commands for the container routing case, though it is a WIP that currently only makes sense for development mode playbook executions. I plan to replace it with a CLI app covering more intended use-cases.
|
As an alternative, you can use the `skato-ansible` shell script in `$ANSIBLE_PROJECT_ROOT` as an abstraction of the `ansible-playbook` commands for the container routing case. I plan to replace it with a CLI app covering more intended use-cases.
|
||||||
|
|
||||||
When using the `skato-ansible.sh` script in development mode for the container routing use case:
|
When using the `skato-ansible.sh` script in development mode for the container routing use case:
|
||||||
|
|
||||||
@@ -196,15 +196,34 @@ When using the `skato-ansible.sh` script in development mode for the container r
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
./skato-ansible.sh init vps -s 0 -v 2 -m dev -n staging0.test
|
./skato-ansible.sh init vps -v 3 -m dev -n staging0.test
|
||||||
./skato-ansible.sh populate-agent staging
|
./skato-ansible.sh populate-agent staging
|
||||||
./skato-ansible.sh bootstrap vps -s 1 -v 2 -m dev -n staging0.test
|
./skato-ansible.sh bootstrap vps -s 1 -v 3 -m dev -n staging0.test
|
||||||
|
|
||||||
./skato-ansible.sh init homeserver -s 0 -v 2 -m dev -n staging1.test
|
./skato-ansible.sh init homeserver -v 3 -m dev -n staging1.test
|
||||||
# BELOW ONLY IF $SKANSIBLE_SSH_KEY ALTERED IN THE SHELL SCRIPT
|
# BELOW ONLY IF $SKANSIBLE_SSH_KEY ALTERED IN THE SHELL SCRIPT
|
||||||
# ./skato-ansible.sh populate-agent staging
|
# ./skato-ansible.sh populate-agent staging
|
||||||
./skato-ansible.sh bootstrap vps -s 1 -v 2 -m dev -n staging1.test
|
./skato-ansible.sh bootstrap vps -s 1 -v 3 -m dev -n staging1.test
|
||||||
|
```
|
||||||
|
|
||||||
|
Otherwise, in production mode:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
#!/bin/bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
INVENTORY_HOSTNAMES=(web1 web2)
|
||||||
|
FQDN=web.site
|
||||||
|
|
||||||
|
./skato-ansible.sh init vps -v 3 -n "${INVENTORY_HOSTNAME[0]}" -d "$FQDN"
|
||||||
|
./skato-ansible.sh populate-agent staging
|
||||||
|
./skato-ansible.sh bootstrap vps -s 1 -v 3 -n "${INVENTORY_HOSTNAME[0]}" -d "$FQDN"
|
||||||
|
|
||||||
|
./skato-ansible.sh init homeserver -v 3 -n "${INVENTORY_HOSTNAME[1]}" -d "$FQDN"
|
||||||
|
# BELOW ONLY IF $SKANSIBLE_SSH_KEY ALTERED IN THE SHELL SCRIPT
|
||||||
|
# ./skato-ansible.sh populate-agent staging
|
||||||
|
./skato-ansible.sh bootstrap vps -s 1 -v 3 -n "${INVENTORY_HOSTNAME[1]}" -d "$FQDN"
|
||||||
```
|
```
|
||||||
|
|
||||||
> [!IMPORTANT]
|
> [!IMPORTANT]
|
||||||
> If you have different SSH keypairs for staging, make sure to change the value of `SKANSIBLE_SSH_KEYS` environment variable in the `${ANSIBLE_PROJECT_ROOT}/skato-ansible.sh` shell script before running the above shell script from `$ANSIBLE_PROJECT_ROOT`.
|
> If you have different SSH keypairs for staging, make sure to change the value of `SKANSIBLE_SSH_KEYS` environment variable in the `${ANSIBLE_PROJECT_ROOT}/skato-ansible.sh` shell script before running the above shell scripts from `$ANSIBLE_PROJECT_ROOT`.
|
||||||
|
|||||||
+23
-21
@@ -15,24 +15,24 @@ if [[ "$1" == "version" ]]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$1" == "show-defaults" ]]; then
|
if [[ "$1" == "show-defaults" ]]; then
|
||||||
source "${SKANSIBLE_SCRIPT_PATH}/.env/bin/activate"
|
source "${SKANSIBLE_SCRIPT_PATH}/.venv/bin/activate"
|
||||||
printf "Private SSH keys available throufh SSH agent: |\n%s\n" "$(ssh-add -l)"
|
printf "Private SSH keys available throufh SSH agent: |\n%s\n" "$(ssh-add -l)"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$1" == "start-agent" ]]; then
|
if [[ "$1" == "start-agent" ]]; then
|
||||||
source "${SKANSIBLE_SCRIPT_PATH}/.env/bin/activate"
|
source "${SKANSIBLE_SCRIPT_PATH}/.venv/bin/activate"
|
||||||
eval "$(ssh-agent -s)"
|
eval "$(ssh-agent -s)"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$1" == "list-agent" ]]; then
|
if [[ "$1" == "list-agent" ]]; then
|
||||||
source "${SKANSIBLE_SCRIPT_PATH}/.env/bin/activate"
|
source "${SKANSIBLE_SCRIPT_PATH}/.venv/bin/activate"
|
||||||
ssh-add -l
|
ssh-add -l
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$1" == "populate-agent" ]]; then
|
if [[ "$1" == "populate-agent" ]]; then
|
||||||
shift 1
|
shift 1
|
||||||
|
|
||||||
source "${SKANSIBLE_SCRIPT_PATH}/.env/bin/activate"
|
source "${SKANSIBLE_SCRIPT_PATH}/.venv/bin/activate"
|
||||||
|
|
||||||
if [[ "$1" == "all" ]]; then
|
if [[ "$1" == "all" ]]; then
|
||||||
for SKANSIBLE_SSH_KEY in ~/.ssh/*; do
|
for SKANSIBLE_SSH_KEY in ~/.ssh/*; do
|
||||||
@@ -69,7 +69,7 @@ fi
|
|||||||
if [[ "$1" == "init" ]]; then
|
if [[ "$1" == "init" ]]; then
|
||||||
shift 1
|
shift 1
|
||||||
|
|
||||||
source "${SKANSIBLE_SCRIPT_PATH}/.env/bin/activate"
|
source "${SKANSIBLE_SCRIPT_PATH}/.venv/bin/activate"
|
||||||
|
|
||||||
if [[ "$1" == "vps" ]]; then
|
if [[ "$1" == "vps" ]]; then
|
||||||
SKANSIBLE_PLAY_HOST="$1"
|
SKANSIBLE_PLAY_HOST="$1"
|
||||||
@@ -82,7 +82,7 @@ if [[ "$1" == "init" ]]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
while getopts "htm:s:n:v:u:" opt; do
|
while getopts "htd:m:s:n:v:u:" opt; do
|
||||||
case $opt in
|
case $opt in
|
||||||
h) Help "init";;
|
h) Help "init";;
|
||||||
s) SKANSIBLE_STAGE="$OPTARG";;
|
s) SKANSIBLE_STAGE="$OPTARG";;
|
||||||
@@ -91,6 +91,7 @@ if [[ "$1" == "init" ]]; then
|
|||||||
t) SKANSIBLE_UNITTEST=True;;
|
t) SKANSIBLE_UNITTEST=True;;
|
||||||
u) export ANSIBLE_REMOTE_USER="$OPTARG";;
|
u) export ANSIBLE_REMOTE_USER="$OPTARG";;
|
||||||
m) SKANSIBLE_MODE="$OPTARG";;
|
m) SKANSIBLE_MODE="$OPTARG";;
|
||||||
|
d) SKANSIBLE_FQDN="$OPTARG";;
|
||||||
*) echo "Err: Invalid option set"; exit 1;;
|
*) echo "Err: Invalid option set"; exit 1;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
@@ -99,23 +100,23 @@ if [[ "$1" == "init" ]]; then
|
|||||||
# SKANSIBLE_CONN_HOST=staging${SKANSIBLE_STAGE}.test
|
# SKANSIBLE_CONN_HOST=staging${SKANSIBLE_STAGE}.test
|
||||||
if [[ "$SKANSIBLE_STAGE" == 0 ]]; then
|
if [[ "$SKANSIBLE_STAGE" == 0 ]]; then
|
||||||
if [[ "$SKANSIBLE_UNITTEST" == "True" ]]; then
|
if [[ "$SKANSIBLE_UNITTEST" == "True" ]]; then
|
||||||
sudo ansible-playbook -CKk -i hosts.yml --extra-vars "chosen_host=${SKANSIBLE_CONN_HOST}" --extra-vars "chosen_user=${ANSIBLE_REMOTE_USER:-root}" --extra-vars "mode=${SKANSIBLE_MODE}" "init@${SKANSIBLE_PLAY_HOST}.yml"
|
sudo ansible-playbook -CKk -i hosts.yml --extra-vars "chosen_host=${SKANSIBLE_CONN_HOST}" --extra-vars "chosen_user=${ANSIBLE_REMOTE_USER:-root}" --extra-vars "mode=${SKANSIBLE_MODE}" --extra-vars "fqdn=${SKANSIBLE_FQDN:-staging.test}" "init@${SKANSIBLE_PLAY_HOST}.yml"
|
||||||
else
|
else
|
||||||
sudo ansible-playbook -Kk -i hosts.yml --extra-vars "chosen_host=${SKANSIBLE_CONN_HOST}" --extra-vars "chosen_user=${ANSIBLE_REMOTE_USER:-root}" --extra-vars "mode=${SKANSIBLE_MODE}" "init@${SKANSIBLE_PLAY_HOST}.yml"
|
sudo ansible-playbook -Kk -i hosts.yml --extra-vars "chosen_host=${SKANSIBLE_CONN_HOST}" --extra-vars "chosen_user=${ANSIBLE_REMOTE_USER:-root}" --extra-vars "mode=${SKANSIBLE_MODE}" --extra-vars "fqdn=${SKANSIBLE_FQDN:-staging.test}" "init@${SKANSIBLE_PLAY_HOST}.yml"
|
||||||
fi
|
fi
|
||||||
elif [[ "$SKANSIBLE_STAGE" == 1 ]]; then
|
elif [[ "$SKANSIBLE_STAGE" == 1 ]]; then
|
||||||
if [[ "$SKANSIBLE_UNITTEST" == "True" ]]; then
|
if [[ "$SKANSIBLE_UNITTEST" == "True" ]]; then
|
||||||
sudo ansible-playbook -CK -i hosts.yml --extra-vars "chosen_host=${SKANSIBLE_CONN_HOST}" --extra-vars "chosen_user=${ANSIBLE_REMOTE_USER:-root}" --extra-vars "mode=${SKANSIBLE_MODE}" "init@${SKANSIBLE_PLAY_HOST}.yml"
|
sudo ansible-playbook -CK -i hosts.yml --extra-vars "chosen_host=${SKANSIBLE_CONN_HOST}" --extra-vars "chosen_user=${ANSIBLE_REMOTE_USER:-root}" --extra-vars "mode=${SKANSIBLE_MODE}" --extra-vars "fqdn=${SKANSIBLE_FQDN:-staging.test}" "init@${SKANSIBLE_PLAY_HOST}.yml"
|
||||||
else
|
else
|
||||||
sudo ansible-playbook -K -i hosts.yml --extra-vars "chosen_host=${SKANSIBLE_CONN_HOST}" --extra-vars "chosen_user=${ANSIBLE_REMOTE_USER:-root}" --extra-vars "mode=${SKANSIBLE_MODE}" "init@${SKANSIBLE_PLAY_HOST}.yml"
|
sudo ansible-playbook -K -i hosts.yml --extra-vars "chosen_host=${SKANSIBLE_CONN_HOST}" --extra-vars "chosen_user=${ANSIBLE_REMOTE_USER:-root}" --extra-vars "mode=${SKANSIBLE_MODE}" --extra-vars "fqdn=${SKANSIBLE_FQDN:-staging.test}" "init@${SKANSIBLE_PLAY_HOST}.yml"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
if [[ -z "$SKANSIBLE_CONN_HOST" ]]; then
|
if [[ -z "$SKANSIBLE_CONN_HOST" ]] && [[ -z "$SKANSIBLE_FQDN" ]]; then
|
||||||
echo "When not doing staging, chosen or preferred host must be made explicit"
|
echo "When not doing staging, chosen or preferred host must be made explicit as well as desired FQDN"
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
sudo ansible-playbook -Kk -i hosts.yml --extra-vars "chosen_host=${SKANSIBLE_CONN_HOST}" --extra-vars "chosen_user=${ANSIBLE_REMOTE_USER:-root}" --extra-vars "mode=prod" "init@${SKANSIBLE_PLAY_HOST}.yml"
|
sudo ansible-playbook -Kk -i hosts.yml --extra-vars "chosen_host=${SKANSIBLE_CONN_HOST}" --extra-vars "chosen_user=${ANSIBLE_REMOTE_USER:-root}" --extra-vars "mode=prod" --extra-vars "fqdn=${SKANSIBLE_FQDN}" "init@${SKANSIBLE_PLAY_HOST}.yml"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -125,7 +126,7 @@ fi
|
|||||||
if [[ "$1" == "bootstrap" ]]; then
|
if [[ "$1" == "bootstrap" ]]; then
|
||||||
shift 1
|
shift 1
|
||||||
|
|
||||||
source "${SKANSIBLE_SCRIPT_PATH}/.env/bin/activate"
|
source "${SKANSIBLE_SCRIPT_PATH}/.venv/bin/activate"
|
||||||
|
|
||||||
if [[ "$1" == "vps" ]]; then
|
if [[ "$1" == "vps" ]]; then
|
||||||
SKANSIBLE_PLAY_HOST="$1"
|
SKANSIBLE_PLAY_HOST="$1"
|
||||||
@@ -138,7 +139,7 @@ if [[ "$1" == "bootstrap" ]]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
while getopts "htm:s:n:v:u:" opt; do
|
while getopts "htd:m:s:n:v:u:" opt; do
|
||||||
case $opt in
|
case $opt in
|
||||||
h) Help "bootstrap";;
|
h) Help "bootstrap";;
|
||||||
s) SKANSIBLE_STAGE="$OPTARG";;
|
s) SKANSIBLE_STAGE="$OPTARG";;
|
||||||
@@ -147,6 +148,7 @@ if [[ "$1" == "bootstrap" ]]; then
|
|||||||
t) SKANSIBLE_UNITTEST=True;;
|
t) SKANSIBLE_UNITTEST=True;;
|
||||||
u) export ANSIBLE_REMOTE_USER="$OPTARG";;
|
u) export ANSIBLE_REMOTE_USER="$OPTARG";;
|
||||||
m) SKANSIBLE_MODE="$OPTARG";;
|
m) SKANSIBLE_MODE="$OPTARG";;
|
||||||
|
d) SKANSIBLE_FQDN="$OPTARG";;
|
||||||
*) echo "Err: Invalid option set"; exit 1;;
|
*) echo "Err: Invalid option set"; exit 1;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
@@ -155,23 +157,23 @@ if [[ "$1" == "bootstrap" ]]; then
|
|||||||
# SKANSIBLE_CONN_HOST=staging${SKANSIBLE_STAGE}.test
|
# SKANSIBLE_CONN_HOST=staging${SKANSIBLE_STAGE}.test
|
||||||
if [[ "$SKANSIBLE_STAGE" == 0 ]]; then
|
if [[ "$SKANSIBLE_STAGE" == 0 ]]; then
|
||||||
if [[ "$SKANSIBLE_UNITTEST" == "True" ]]; then
|
if [[ "$SKANSIBLE_UNITTEST" == "True" ]]; then
|
||||||
ansible-playbook -CKk -i hosts.yml --extra-vars "chosen_host=${SKANSIBLE_CONN_HOST}" --extra-vars "chosen_user=${ANSIBLE_REMOTE_USER:-senpai}" --extra-vars "mode=${SKANSIBLE_MODE}" "administrate@${SKANSIBLE_PLAY_HOST}.yml"
|
ansible-playbook -CKk -i hosts.yml --extra-vars "chosen_host=${SKANSIBLE_CONN_HOST}" --extra-vars "chosen_user=${ANSIBLE_REMOTE_USER:-senpai}" --extra-vars "mode=${SKANSIBLE_MODE}" --extra-vars "fqdn=${SKANSIBLE_FQDN:-staging.test}" "administrate@${SKANSIBLE_PLAY_HOST}.yml"
|
||||||
else
|
else
|
||||||
ansible-playbook -Kk -i hosts.yml --extra-vars "chosen_host=${SKANSIBLE_CONN_HOST}" --extra-vars "chosen_user=${ANSIBLE_REMOTE_USER:-senpai}" --extra-vars "mode=${SKANSIBLE_MODE}" "administrate@${SKANSIBLE_PLAY_HOST}.yml"
|
ansible-playbook -Kk -i hosts.yml --extra-vars "chosen_host=${SKANSIBLE_CONN_HOST}" --extra-vars "chosen_user=${ANSIBLE_REMOTE_USER:-senpai}" --extra-vars "mode=${SKANSIBLE_MODE}" --extra-vars "fqdn=${SKANSIBLE_FQDN:-staging.test}" "administrate@${SKANSIBLE_PLAY_HOST}.yml"
|
||||||
fi
|
fi
|
||||||
elif [[ "$SKANSIBLE_STAGE" == 1 ]]; then
|
elif [[ "$SKANSIBLE_STAGE" == 1 ]]; then
|
||||||
if [[ "$SKANSIBLE_UNITTEST" == "True" ]]; then
|
if [[ "$SKANSIBLE_UNITTEST" == "True" ]]; then
|
||||||
ansible-playbook -CK -i hosts.yml --extra-vars "chosen_host=${SKANSIBLE_CONN_HOST}" --extra-vars "chosen_user=${ANSIBLE_REMOTE_USER:-senpai}" --extra-vars "mode=${SKANSIBLE_MODE}" "administrate@${SKANSIBLE_PLAY_HOST}.yml"
|
ansible-playbook -CK -i hosts.yml --extra-vars "chosen_host=${SKANSIBLE_CONN_HOST}" --extra-vars "chosen_user=${ANSIBLE_REMOTE_USER:-senpai}" --extra-vars "mode=${SKANSIBLE_MODE}" --extra-vars "fqdn=${SKANSIBLE_FQDN:-staging.test}" "administrate@${SKANSIBLE_PLAY_HOST}.yml"
|
||||||
else
|
else
|
||||||
ansible-playbook -K -i hosts.yml --extra-vars "chosen_host=${SKANSIBLE_CONN_HOST}" --extra-vars "chosen_user=${ANSIBLE_REMOTE_USER:-senpai}" --extra-vars "mode=${SKANSIBLE_MODE}" "administrate@${SKANSIBLE_PLAY_HOST}.yml"
|
ansible-playbook -K -i hosts.yml --extra-vars "chosen_host=${SKANSIBLE_CONN_HOST}" --extra-vars "chosen_user=${ANSIBLE_REMOTE_USER:-senpai}" --extra-vars "mode=${SKANSIBLE_MODE}" --extra-vars "fqdn=${SKANSIBLE_FQDN:-staging.test}" "administrate@${SKANSIBLE_PLAY_HOST}.yml"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
if [[ -z "$SKANSIBLE_CONN_HOST" ]]; then
|
if [[ -z "$SKANSIBLE_CONN_HOST" ]]; then
|
||||||
echo "When not doing staging, chosen or preferred host must be made explicit"
|
echo "When not doing staging, chosen or preferred host must be made explicit as well as desired FQDN"
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
ansible-playbook -Kk -i hosts.yml --extra-vars "chosen_host=${SKANSIBLE_CONN_HOST}" --extra-vars "chosen_user=${ANSIBLE_REMOTE_USER:-senpai}" --extra-vars "mode=prod" "administrate@${SKANSIBLE_PLAY_HOST}.yml"
|
ansible-playbook -Kk -i hosts.yml --extra-vars "chosen_host=${SKANSIBLE_CONN_HOST}" --extra-vars "chosen_user=${ANSIBLE_REMOTE_USER:-senpai}" --extra-vars "mode=prod" --extra-vars "fqdn=${SKANSIBLE_FQDN}" "administrate@${SKANSIBLE_PLAY_HOST}.yml"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user