Files
homelab-infra/.gitea/workflows/netbird-install.yml
T

71 lines
2.3 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
name: netbird-install
on:
workflow_dispatch:
inputs:
letsencrypt_email:
description: Почта для уведомлений Let's Encrypt
required: true
type: string
jobs:
install:
runs-on: homelab
timeout-minutes: 30
steps:
- name: Запустить плейбук NetBird
env:
RUNNER_SSH_KEY: ${{ secrets.RUNNER_SSH_KEY }}
NETBIRD_LETSENCRYPT_EMAIL: ${{ inputs.letsencrypt_email }}
run: |
set -eu
if [ -z "${RUNNER_SSH_KEY}" ]; then
echo "В секретах нет RUNNER_SSH_KEY." >&2
exit 1
fi
if [ -z "${NETBIRD_LETSENCRYPT_EMAIL}" ]; then
echo "Укажите почту Let's Encrypt при запуске." >&2
exit 1
fi
if [ "$(id -u)" -eq 0 ]; then
apt-get update
apt-get install -y git openssh-client ansible-core
else
sudo apt-get update
sudo apt-get install -y git openssh-client ansible-core
fi
rm -rf /tmp/homelab-infra
git clone https://gitea.gunihome.ru/karpenok/homelab-infra.git /tmp/homelab-infra
sha="${GITHUB_SHA:-${GITEA_SHA:-}}"
if [ -n "${sha}" ]; then
git -C /tmp/homelab-infra checkout "${sha}"
fi
install -d -m 700 "${HOME}/.ssh"
printf '%s\n' "${RUNNER_SSH_KEY}" > "${HOME}/.ssh/id_ed25519"
chmod 600 "${HOME}/.ssh/id_ed25519"
inventory=/tmp/homelab-infra/inventory/hosts.ini
target=$(awk '{
for (i = 1; i <= NF; i++) {
if ($i ~ /^ansible_host=/) {
split($i, a, "=")
print a[2]
exit
}
}
}' "${inventory}")
if [ -z "${target}" ]; then
echo "В inventory/hosts.ini нет ansible_host." >&2
exit 1
fi
echo "Цель из inventory: ${target}"
ssh-keyscan -H "${target}" >> "${HOME}/.ssh/known_hosts"
ansible-playbook /tmp/homelab-infra/services/netbird/playbook.yml \
-i "${inventory}" \
--private-key "${HOME}/.ssh/id_ed25519" \
-e "netbird_letsencrypt_email=${NETBIRD_LETSENCRYPT_EMAIL}"