--- - name: Разрешить порты панели ansible.builtin.command: ufw allow {{ item }} register: ufw_rule changed_when: "'added' in (ufw_rule.stdout | lower)" loop: "{{ netbird_ports }}" - name: Поставить openssl, curl и jq ansible.builtin.apt: name: - openssl - curl - jq state: present - name: Создать каталог панели ansible.builtin.file: path: "{{ netbird_dir }}" state: directory owner: root group: root mode: "0700" - name: Проверить наличие обязательных секретов NetBird ansible.builtin.assert: that: - netbird_domain is defined and netbird_domain | length > 3 - netbird_auth_secret is defined and netbird_auth_secret | length > 0 - netbird_datastore_key is defined and netbird_datastore_key | length > 0 - netbird_session_key is defined and netbird_session_key | length > 0 - netbird_letsencrypt_email is defined and netbird_letsencrypt_email | length > 3 - netbird_admin_email is defined and netbird_admin_email | length > 3 - netbird_admin_name is defined and netbird_admin_name | length > 0 - netbird_admin_password is defined and netbird_admin_password | length >= 8 fail_msg: "Не задан домен NetBird (host_vars) или один из секретов NETBIRD_AUTH_SECRET, NETBIRD_DATASTORE_KEY, NETBIRD_SESSION_KEY, NETBIRD_LETSENCRYPT_EMAIL, NETBIRD_ADMIN_EMAIL, NETBIRD_ADMIN_NAME, NETBIRD_ADMIN_PASSWORD (мин. 8 символов)." - name: Записать .env ansible.builtin.template: src: env.j2 dest: "{{ netbird_dir }}/.env" owner: root group: root mode: "0600" no_log: true notify: Перезапустить NetBird - name: Положить манифест панели ansible.builtin.copy: src: compose.yaml dest: "{{ netbird_dir }}/compose.yaml" owner: root group: root mode: "0644" notify: Перезапустить NetBird - name: Собрать dashboard.env ansible.builtin.template: src: dashboard.env.j2 dest: "{{ netbird_dir }}/dashboard.env" owner: root group: root mode: "0644" notify: Перезапустить NetBird - name: Собрать config.yaml ansible.builtin.template: src: config.yaml.j2 dest: "{{ netbird_dir }}/config.yaml" owner: root group: root mode: "0600" no_log: true notify: Перезапустить NetBird - name: Применить изменения конфигурации ansible.builtin.meta: flush_handlers - name: Убедиться, что панель запущена ansible.builtin.command: docker compose up -d args: chdir: "{{ netbird_dir }}" register: compose_up changed_when: "'Started' in compose_up.stderr or 'Created' in compose_up.stderr or 'Recreated' in compose_up.stderr" - name: Показать состояние контейнеров ansible.builtin.command: docker compose ps args: chdir: "{{ netbird_dir }}" register: compose_ps changed_when: false - name: Дождаться ответа панели и API ansible.builtin.command: > curl -fsSk --resolve {{ netbird_domain }}:443:127.0.0.1 https://{{ netbird_domain }}/api/instance register: instance_status changed_when: false retries: 30 delay: 5 until: instance_status.rc == 0 and ('setup_required' in instance_status.stdout) - name: Настроить системный каркас NetBird ansible.builtin.include_tasks: bootstrap.yml - name: Синхронизировать доступ и клиентов NetBird из access.yml ansible.builtin.include_tasks: access.yml # Токен перевыпускается ролью, поэтому регистрация берёт его из Infisical # при каждом прогоне: агент не остаётся с протухшим креденшлом. - name: Зарегистрировать панель NetBird в Agent Vault ansible.builtin.include_role: name: agent_vault_service vars: agent_vault_service_name: netbird agent_vault_service_description: >- Панель NetBird (central.gunihome.ru): пиры, пользователи, setup-ключи и маршруты оверлейной сети. Креденшл — сервисный API-токен. agent_vault_service_host: "{{ netbird_domain }}:443" agent_vault_service_paths: ["/api"] agent_vault_service_methods: [GET] agent_vault_service_header_prefix: Token agent_vault_secret_path: /services/netbird agent_vault_secret_key: NETBIRD_API_TOKEN - name: Итог установки ansible.builtin.debug: msg: - "Панель: https://{{ netbird_domain }}" - "Суперпользователь создан в этом прогоне: {{ netbird_bootstrap_state.admin_created }}" - "API-токен обновлен в Infisical: {{ netbird_bootstrap_state.token_updated }}" - "Setup-ключ роутеров обновлен в Infisical: {{ netbird_bootstrap_state.setup_key_updated }}" - "Ключ remnawave-peers обновлен в Infisical: {{ netbird_bootstrap_state.remnawave_setup_key_updated }}" - "Маршрут {{ netbird_lan_subnet }} создан в этом прогоне: {{ netbird_bootstrap_state.route_created }}" - "Изменения доступа (access.yml): {{ netbird_access_summary.changes }}" - "Обновлённые секреты клиентов в Infisical: {{ netbird_access_summary.updated_secret_names }}" - "Предупреждения access.yml: {{ netbird_access_summary.warnings }}"