This repository has been archived on 2023-02-09. You can view files and clone it, but cannot push or open issues or pull requests.
drone-ansible-runner/entrypoint

69 lines
1.5 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}
2021-12-15 17:50:23 +01:00
run_command(){
2022-04-26 11:24:48 +02:00
echo "\t➡ $@"
2021-12-15 18:07:45 +01:00
$@
2021-12-15 17:50:23 +01:00
}
2021-12-15 00:21:52 +01:00
if [[ -z "$PLUGIN_PLAYBOOK" ]]; then
2022-04-26 11:24:48 +02:00
echo -e "⚠️ \e[31m'playbook' setting not defined, ABORT!\e[39m"
2021-12-15 00:21:52 +01:00
exit 1
fi
2022-03-12 23:54:05 +01:00
if [[ -z "$PLUGIN_PRIVATE_KEY" ]]; then
2022-04-26 11:24:48 +02:00
echo -e "⚠️ \e[31m[WARN] 'private_key' setting not defined !\e[39m"
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
2021-12-15 00:21:52 +01:00
if [[ -n "$PLUGIN_VAULT_TOKEN" ]]; then
2022-04-26 11:24:48 +02:00
echo "💼 Adding vault token to 'credentials/vault_token'"
2021-12-15 18:07:45 +01:00
run_command "mkdir credentials"
echo "$PLUGIN_VAULT_TOKEN" > credentials/vault_token
2022-03-04 15:37:11 +01:00
args+=("--vault-password-file" "credentials/vault_token")
2021-12-15 00:21:52 +01:00
echo ""
fi
2022-01-23 18:21:24 +01:00
if [[ -f "ansible-ci.cfg" ]]; then
rm ansible.cfg
mv ansible-ci.cfg ansible.cfg
fi
2021-12-15 00:21:52 +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[@]}"