up
This commit is contained in:
1 parent
00a0615750
commit
5f91f7bc95
6 files changed
+51
-21
No files matched your search
@@ -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 \
|
||||
|
||||
@@ -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
|
||||
+4
-1
@@ -3,4 +3,7 @@
|
||||
hosts: all
|
||||
gather_facts: false
|
||||
roles:
|
||||
- host
|
||||
- role: host
|
||||
tags:
|
||||
- host
|
||||
- system
|
||||
@@ -3,4 +3,8 @@
|
||||
hosts: netbird
|
||||
gather_facts: false
|
||||
roles:
|
||||
- netbird
|
||||
- role: netbird
|
||||
tags:
|
||||
- netbird
|
||||
- vpn
|
||||
- config
|
||||
@@ -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"
|
||||
|
||||
@@ -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
|
||||
Reference in new issue
Block a user