Files
homelab-infra/ansible/roles/netbird/tasks/main.yml
T
2026-11-10 16:44:23 +07:00

119 lines
3.3 KiB
YAML

---
- name: Разрешить порты панели
ansible.builtin.command: ufw allow {{ item }}
register: ufw_rule
changed_when: "'added' in (ufw_rule.stdout | lower)"
loop: "{{ netbird_ports }}"
- name: Поставить openssl
ansible.builtin.apt:
name: openssl
state: present
- name: Создать каталог панели
ansible.builtin.file:
path: "{{ netbird_dir }}"
state: directory
owner: root
group: root
mode: "0700"
- name: Проверить наличие обязательных секретов NetBird
ansible.builtin.assert:
that:
- 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
fail_msg: "Один или несколько обязательных секретов NetBird (NETBIRD_AUTH_SECRET, NETBIRD_DATASTORE_KEY, NETBIRD_SESSION_KEY, NETBIRD_LETSENCRYPT_EMAIL) не переданы из Infisical!"
tags:
- config
- name: Записать .env
ansible.builtin.template:
src: env.j2
dest: "{{ netbird_dir }}/.env"
owner: root
group: root
mode: "0600"
no_log: true
notify: Перезапустить NetBird
tags:
- config
- name: Положить манифест панели
ansible.builtin.copy:
src: compose.yaml
dest: "{{ netbird_dir }}/compose.yaml"
owner: root
group: root
mode: "0644"
notify: Перезапустить NetBird
tags:
- config
- name: Собрать dashboard.env
ansible.builtin.template:
src: dashboard.env.j2
dest: "{{ netbird_dir }}/dashboard.env"
owner: root
group: root
mode: "0644"
notify: Перезапустить NetBird
tags:
- config
- 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
tags:
- config
- name: Применить изменения конфигурации
ansible.builtin.meta: flush_handlers
tags:
- config
- 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"
tags:
- config
- name: Показать состояние контейнеров
ansible.builtin.command: docker compose ps
args:
chdir: "{{ netbird_dir }}"
register: compose_ps
changed_when: false
tags:
- config
- name: Дождаться ответа панели
ansible.builtin.command: >
curl -sk --resolve {{ netbird_domain }}:443:127.0.0.1
-o /dev/null -w '%{http_code}'
https://{{ netbird_domain }}/
register: panel_http
changed_when: false
retries: 30
delay: 10
until: panel_http.stdout in ['200', '302']
tags:
- config
- name: Итог установки
ansible.builtin.debug:
msg: "{{ compose_ps.stdout_lines + ['Первый вход: https://' + netbird_domain + '/setup'] }}"
tags:
- config