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 python3 else sudo apt-get update sudo apt-get install -y git openssh-client ansible-core python3 fi rm -rf "${HOME}/homelab-infra" git clone https://gitea.gunihome.ru/karpenok/homelab-infra.git "${HOME}/homelab-infra" sha="${GITHUB_SHA:-${GITEA_SHA:-}}" if [ -n "${sha}" ]; then git -C "${HOME}/homelab-infra" checkout "${sha}" fi chmod -R go-w "${HOME}/homelab-infra" install -d -m 700 "${HOME}/.ssh" printf '%s\n' "${RUNNER_SSH_KEY}" > "${HOME}/.ssh/id_ed25519" chmod 600 "${HOME}/.ssh/id_ed25519" cd "${HOME}/homelab-infra" ansible-inventory -i inventories/prod/hosts.yml --list > /tmp/inventory.json python3 - <<'PY' import json, subprocess data = json.load(open("/tmp/inventory.json")) hosts = data.get("netbird", {}).get("hosts", []) hostvars = data.get("_meta", {}).get("hostvars", {}) targets = [] for name in hosts: address = hostvars.get(name, {}).get("ansible_host") if not address: raise SystemExit(f"У {name} нет ansible_host") targets.append(address) if not targets: raise SystemExit("В группе netbird нет машин") print("Цели из inventory:", ", ".join(targets)) for address in targets: subprocess.check_call(["ssh-keyscan", "-H", address], stdout=open(f"{__import__('os').environ['HOME']}/.ssh/known_hosts", "a")) PY ansible-playbook playbooks/site.yml \ -i inventories/prod/hosts.yml \ --limit netbird \ --private-key "${HOME}/.ssh/id_ed25519" \ -e "netbird_letsencrypt_email=${NETBIRD_LETSENCRYPT_EMAIL}"