woodpecker-ansible-runner/entrypoint

82 lines
1.9 KiB
Plaintext
Raw Normal View History

2021-12-15 00:21:52 +01:00
#!/bin/bash
check=${PLUGIN_CHECK_SYNTAX:-false}
verbosity=${PLUGIN_VERBOSITY:-0}
2022-12-29 12:14:09 +01:00
C_RESET="\e[39m"
C_RED="\e[31m"
C_YELLOW="\e[33m"
C_BLUE="\e[34m"
2021-12-15 17:50:23 +01:00
run_command(){
2022-04-26 11:24:48 +02:00
echo "➡️ $@"
2021-12-15 18:07:45 +01:00
$@
2021-12-15 17:50:23 +01:00
}
2022-12-29 12:14:09 +01:00
echo -e "${C_BLUE}"
toilet -f smblock Woodpecker Ansible
toilet -f smblock " Runner"
echo -e "${C_RESET}"
2021-12-15 17:50:23 +01:00
2022-12-18 16:18:24 +01:00
if [ -z "$PLUGIN_PLAYBOOK" ]; then
2022-12-29 12:14:09 +01:00
echo -e "⚠️ ${C_RED}'playbook' setting not defined, ABORT!${C_RESET}"
2021-12-15 00:21:52 +01:00
exit 1
fi
2022-12-18 16:18:24 +01:00
if [ -z "$PLUGIN_PRIVATE_KEY" ]; then
2022-12-29 12:14:09 +01:00
echo -e "⚠️ ${C_YELLOW}[WARN] 'private_key' setting not defined !${C_RESET}"
2022-03-12 23:54:05 +01:00
else
run_command "mkdir /root/.ssh"
echo "$PLUGIN_PRIVATE_KEY" > /root/.ssh/id_ed25519
run_command chmod 400 /root/.ssh/id_ed25519
fi
2021-12-15 00:21:52 +01:00
2022-03-04 15:37:11 +01:00
args=("$PLUGIN_PLAYBOOK")
2022-01-23 18:21:24 +01:00
2022-12-18 16:18:24 +01:00
if [ -n "$PLUGIN_VAULT_TOKEN" ]; then
2023-04-20 19:45:45 +02:00
echo "💼 Adding vault token to 'credentials/ci_vault_token'"
2021-12-15 18:07:45 +01:00
run_command "mkdir credentials"
2023-04-20 19:45:45 +02:00
echo "$PLUGIN_VAULT_TOKEN" > credentials/ci_vault_token
2023-04-21 20:57:50 +02:00
args+=("--vault-password-file=credentials/ci_vault_token")
2023-04-22 11:56:05 +02:00
echo "⚙️ Clean ansible.cfg"
2023-04-22 12:10:20 +02:00
echo "➡️ sed -i '/vault_password_file.*/d' ./ansible.cfg"
sed -i '/vault_password_file.*/d' ./ansible.cfg
2021-12-15 00:21:52 +01:00
echo ""
fi
2022-12-18 16:18:24 +01:00
if [ -f "ansible-ci.cfg" ]; then
echo "⚙️ ansible-ci.cfg is present, using it."
2022-01-23 18:21:24 +01:00
rm ansible.cfg
mv ansible-ci.cfg ansible.cfg
2022-12-18 16:18:24 +01:00
echo ""
2022-01-23 18:21:24 +01:00
fi
2022-12-18 16:18:24 +01:00
if [ -n "$PLUGIN_GALAXY_FILE" ]; then
2022-04-26 11:24:48 +02:00
echo "🚀 Installing Galaxy dependencies ($PLUGIN_GALAXY_FILE)"
2021-12-15 18:07:45 +01:00
run_command "ansible-galaxy install -r $PLUGIN_GALAXY_FILE --force"
2021-12-15 00:21:52 +01:00
echo ""
fi
if [[ $check = true ]]; then
2022-03-04 15:37:11 +01:00
args+=("--syntax-check")
2021-12-15 00:21:52 +01:00
fi
if [[ $verbosity != "0" ]]; then
2022-03-04 15:37:11 +01:00
verb="-"
2021-12-15 00:21:52 +01:00
for i in `seq 1 $verbosity`; do
2022-03-04 15:37:11 +01:00
verb+="v"
2021-12-15 00:21:52 +01:00
done
2022-03-04 15:37:11 +01:00
args+=("$verb")
2021-12-15 00:21:52 +01:00
fi
if [[ -n "$PLUGIN_LIMIT" ]]; then
2022-03-04 16:19:53 +01:00
args+=("--limit" "$PLUGIN_LIMIT")
2021-12-15 00:21:52 +01:00
fi
2022-02-28 11:27:38 +01:00
if [[ -n "$PLUGIN_TAGS" ]]; then
2022-03-04 16:19:53 +01:00
args+=("--tags" "$PLUGIN_TAGS")
2022-02-28 11:27:38 +01:00
fi
2021-12-15 18:07:45 +01:00
run_command "export ANSIBLE_HOST_KEY_CHECKING=False"
2022-04-26 11:24:48 +02:00
echo "➡️ ansible-playbook ${args[@]}"
2022-03-04 15:37:11 +01:00
ansible-playbook "${args[@]}"