From 5f91f7bc9598f0d0226c035d49b5edb18a764ed1 Mon Sep 17 00:00:00 2001 From: karpenok Date: Sun, 8 Nov 2026 11:36:41 +0700 Subject: [PATCH] up --- .gitea/workflows/netbird-install.yml | 18 ---------------- ansible.cfg | 4 ++++ playbooks/host.yml | 5 ++++- playbooks/netbird.yml | 6 +++++- roles/netbird/handlers/main.yml | 8 +++++++ roles/netbird/tasks/main.yml | 31 +++++++++++++++++++++++++++- 6 files changed, 51 insertions(+), 21 deletions(-) create mode 100644 roles/netbird/handlers/main.yml diff --git a/.gitea/workflows/netbird-install.yml b/.gitea/workflows/netbird-install.yml index 245be36..68ed1d4 100644 --- a/.gitea/workflows/netbird-install.yml +++ b/.gitea/workflows/netbird-install.yml @@ -49,24 +49,6 @@ jobs: 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 \ diff --git a/ansible.cfg b/ansible.cfg index b9fcec0..ca7b89e 100644 --- a/ansible.cfg +++ b/ansible.cfg @@ -3,3 +3,7 @@ inventory = inventories/prod/hosts.yml roles_path = roles retry_files_enabled = false stdout_callback = yaml + +[ssh_connection] +pipelining = True +ssh_args = -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=accept-new diff --git a/playbooks/host.yml b/playbooks/host.yml index a461f61..11b65e0 100644 --- a/playbooks/host.yml +++ b/playbooks/host.yml @@ -3,4 +3,7 @@ hosts: all gather_facts: false roles: - - host + - role: host + tags: + - host + - system diff --git a/playbooks/netbird.yml b/playbooks/netbird.yml index cdd0f00..506ebd1 100644 --- a/playbooks/netbird.yml +++ b/playbooks/netbird.yml @@ -3,4 +3,8 @@ hosts: netbird gather_facts: false roles: - - netbird + - role: netbird + tags: + - netbird + - vpn + - config diff --git a/roles/netbird/handlers/main.yml b/roles/netbird/handlers/main.yml new file mode 100644 index 0000000..1fb22b9 --- /dev/null +++ b/roles/netbird/handlers/main.yml @@ -0,0 +1,8 @@ +--- +- name: Перезапустить NetBird + ansible.builtin.command: docker compose up -d --remove-orphans + 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" + diff --git a/roles/netbird/tasks/main.yml b/roles/netbird/tasks/main.yml index 43ad2cd..098ba2e 100644 --- a/roles/netbird/tasks/main.yml +++ b/roles/netbird/tasks/main.yml @@ -22,6 +22,8 @@ ansible.builtin.stat: path: "{{ netbird_dir }}/.env" register: netbird_env + tags: + - config - name: Проверить почту Let's Encrypt ansible.builtin.assert: @@ -56,6 +58,8 @@ register: netbird_env_raw no_log: true when: netbird_env.stat.exists + tags: + - config - name: Разобрать сохранённые ключи ansible.builtin.set_fact: @@ -68,6 +72,8 @@ env_map: "{{ dict(env_lines | map('split', '=', 1)) }}" no_log: true when: netbird_env.stat.exists + tags: + - config - name: Записать .env ansible.builtin.template: @@ -77,6 +83,7 @@ group: root mode: "0600" no_log: true + notify: Перезапустить NetBird when: not netbird_env.stat.exists - name: Положить манифест панели @@ -86,6 +93,9 @@ owner: root group: root mode: "0644" + notify: Перезапустить NetBird + tags: + - config - name: Собрать dashboard.env ansible.builtin.template: @@ -94,6 +104,9 @@ owner: root group: root mode: "0644" + notify: Перезапустить NetBird + tags: + - config - name: Собрать config.yaml ansible.builtin.template: @@ -103,13 +116,23 @@ group: root mode: "0600" no_log: true + notify: Перезапустить NetBird + tags: + - config -- name: Поднять панель +- 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 @@ -117,6 +140,8 @@ chdir: "{{ netbird_dir }}" register: compose_ps changed_when: false + tags: + - config - name: Дождаться ответа панели ansible.builtin.command: > @@ -128,7 +153,11 @@ 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