woodpecker-ansible-runner/entrypoint
SebClem 33754d87f8
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/deployment/woodpecker Pipeline was successful
Fix sed command
2023-04-22 12:10:20 +02:00

82 lines
1.9 KiB
Bash
Executable File

#!/bin/bash
check=${PLUGIN_CHECK_SYNTAX:-false}
verbosity=${PLUGIN_VERBOSITY:-0}
C_RESET="\e[39m"
C_RED="\e[31m"
C_YELLOW="\e[33m"
C_BLUE="\e[34m"
run_command(){
echo "➡️ $@"
$@
}
echo -e "${C_BLUE}"
toilet -f smblock Woodpecker Ansible
toilet -f smblock " Runner"
echo -e "${C_RESET}"
if [ -z "$PLUGIN_PLAYBOOK" ]; then
echo -e "⚠️ ${C_RED}'playbook' setting not defined, ABORT!${C_RESET}"
exit 1
fi
if [ -z "$PLUGIN_PRIVATE_KEY" ]; then
echo -e "⚠️ ${C_YELLOW}[WARN] 'private_key' setting not defined !${C_RESET}"
else
run_command "mkdir /root/.ssh"
echo "$PLUGIN_PRIVATE_KEY" > /root/.ssh/id_ed25519
run_command chmod 400 /root/.ssh/id_ed25519
fi
args=("$PLUGIN_PLAYBOOK")
if [ -n "$PLUGIN_VAULT_TOKEN" ]; then
echo "💼 Adding vault token to 'credentials/ci_vault_token'"
run_command "mkdir credentials"
echo "$PLUGIN_VAULT_TOKEN" > credentials/ci_vault_token
args+=("--vault-password-file=credentials/ci_vault_token")
echo "⚙️ Clean ansible.cfg"
echo "➡️ sed -i '/vault_password_file.*/d' ./ansible.cfg"
sed -i '/vault_password_file.*/d' ./ansible.cfg
echo ""
fi
if [ -f "ansible-ci.cfg" ]; then
echo "⚙️ ansible-ci.cfg is present, using it."
rm ansible.cfg
mv ansible-ci.cfg ansible.cfg
echo ""
fi
if [ -n "$PLUGIN_GALAXY_FILE" ]; then
echo "🚀 Installing Galaxy dependencies ($PLUGIN_GALAXY_FILE)"
run_command "ansible-galaxy install -r $PLUGIN_GALAXY_FILE --force"
echo ""
fi
if [[ $check = true ]]; then
args+=("--syntax-check")
fi
if [[ $verbosity != "0" ]]; then
verb="-"
for i in `seq 1 $verbosity`; do
verb+="v"
done
args+=("$verb")
fi
if [[ -n "$PLUGIN_LIMIT" ]]; then
args+=("--limit" "$PLUGIN_LIMIT")
fi
if [[ -n "$PLUGIN_TAGS" ]]; then
args+=("--tags" "$PLUGIN_TAGS")
fi
run_command "export ANSIBLE_HOST_KEY_CHECKING=False"
echo "➡️ ansible-playbook ${args[@]}"
ansible-playbook "${args[@]}"