up
This commit is contained in:
1 parent
00a0615750
commit
5f91f7bc95
6 files changed
+49
-19
No files matched your search
@@ -49,24 +49,6 @@ jobs:
|
|||||||
chmod 600 "${HOME}/.ssh/id_ed25519"
|
chmod 600 "${HOME}/.ssh/id_ed25519"
|
||||||
|
|
||||||
cd "${HOME}/homelab-infra"
|
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 \
|
ansible-playbook playbooks/site.yml \
|
||||||
-i inventories/prod/hosts.yml \
|
-i inventories/prod/hosts.yml \
|
||||||
|
|||||||
@@ -3,3 +3,7 @@ inventory = inventories/prod/hosts.yml
|
|||||||
roles_path = roles
|
roles_path = roles
|
||||||
retry_files_enabled = false
|
retry_files_enabled = false
|
||||||
stdout_callback = yaml
|
stdout_callback = yaml
|
||||||
|
|
||||||
|
[ssh_connection]
|
||||||
|
pipelining = True
|
||||||
|
ssh_args = -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=accept-new
|
||||||
@@ -3,4 +3,7 @@
|
|||||||
hosts: all
|
hosts: all
|
||||||
gather_facts: false
|
gather_facts: false
|
||||||
roles:
|
roles:
|
||||||
|
- role: host
|
||||||
|
tags:
|
||||||
- host
|
- host
|
||||||
|
- system
|
||||||
@@ -3,4 +3,8 @@
|
|||||||
hosts: netbird
|
hosts: netbird
|
||||||
gather_facts: false
|
gather_facts: false
|
||||||
roles:
|
roles:
|
||||||
|
- role: netbird
|
||||||
|
tags:
|
||||||
- netbird
|
- 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:
|
ansible.builtin.stat:
|
||||||
path: "{{ netbird_dir }}/.env"
|
path: "{{ netbird_dir }}/.env"
|
||||||
register: netbird_env
|
register: netbird_env
|
||||||
|
tags:
|
||||||
|
- config
|
||||||
|
|
||||||
- name: Проверить почту Let's Encrypt
|
- name: Проверить почту Let's Encrypt
|
||||||
ansible.builtin.assert:
|
ansible.builtin.assert:
|
||||||
@@ -56,6 +58,8 @@
|
|||||||
register: netbird_env_raw
|
register: netbird_env_raw
|
||||||
no_log: true
|
no_log: true
|
||||||
when: netbird_env.stat.exists
|
when: netbird_env.stat.exists
|
||||||
|
tags:
|
||||||
|
- config
|
||||||
|
|
||||||
- name: Разобрать сохранённые ключи
|
- name: Разобрать сохранённые ключи
|
||||||
ansible.builtin.set_fact:
|
ansible.builtin.set_fact:
|
||||||
@@ -68,6 +72,8 @@
|
|||||||
env_map: "{{ dict(env_lines | map('split', '=', 1)) }}"
|
env_map: "{{ dict(env_lines | map('split', '=', 1)) }}"
|
||||||
no_log: true
|
no_log: true
|
||||||
when: netbird_env.stat.exists
|
when: netbird_env.stat.exists
|
||||||
|
tags:
|
||||||
|
- config
|
||||||
|
|
||||||
- name: Записать .env
|
- name: Записать .env
|
||||||
ansible.builtin.template:
|
ansible.builtin.template:
|
||||||
@@ -77,6 +83,7 @@
|
|||||||
group: root
|
group: root
|
||||||
mode: "0600"
|
mode: "0600"
|
||||||
no_log: true
|
no_log: true
|
||||||
|
notify: Перезапустить NetBird
|
||||||
when: not netbird_env.stat.exists
|
when: not netbird_env.stat.exists
|
||||||
|
|
||||||
- name: Положить манифест панели
|
- name: Положить манифест панели
|
||||||
@@ -86,6 +93,9 @@
|
|||||||
owner: root
|
owner: root
|
||||||
group: root
|
group: root
|
||||||
mode: "0644"
|
mode: "0644"
|
||||||
|
notify: Перезапустить NetBird
|
||||||
|
tags:
|
||||||
|
- config
|
||||||
|
|
||||||
- name: Собрать dashboard.env
|
- name: Собрать dashboard.env
|
||||||
ansible.builtin.template:
|
ansible.builtin.template:
|
||||||
@@ -94,6 +104,9 @@
|
|||||||
owner: root
|
owner: root
|
||||||
group: root
|
group: root
|
||||||
mode: "0644"
|
mode: "0644"
|
||||||
|
notify: Перезапустить NetBird
|
||||||
|
tags:
|
||||||
|
- config
|
||||||
|
|
||||||
- name: Собрать config.yaml
|
- name: Собрать config.yaml
|
||||||
ansible.builtin.template:
|
ansible.builtin.template:
|
||||||
@@ -103,13 +116,23 @@
|
|||||||
group: root
|
group: root
|
||||||
mode: "0600"
|
mode: "0600"
|
||||||
no_log: true
|
no_log: true
|
||||||
|
notify: Перезапустить NetBird
|
||||||
|
tags:
|
||||||
|
- config
|
||||||
|
|
||||||
- name: Поднять панель
|
- name: Применить изменения конфигурации
|
||||||
|
ansible.builtin.meta: flush_handlers
|
||||||
|
tags:
|
||||||
|
- config
|
||||||
|
|
||||||
|
- name: Убедиться, что панель запущена
|
||||||
ansible.builtin.command: docker compose up -d
|
ansible.builtin.command: docker compose up -d
|
||||||
args:
|
args:
|
||||||
chdir: "{{ netbird_dir }}"
|
chdir: "{{ netbird_dir }}"
|
||||||
register: compose_up
|
register: compose_up
|
||||||
changed_when: "'Started' in compose_up.stderr or 'Created' in compose_up.stderr or 'Recreated' in compose_up.stderr"
|
changed_when: "'Started' in compose_up.stderr or 'Created' in compose_up.stderr or 'Recreated' in compose_up.stderr"
|
||||||
|
tags:
|
||||||
|
- config
|
||||||
|
|
||||||
- name: Показать состояние контейнеров
|
- name: Показать состояние контейнеров
|
||||||
ansible.builtin.command: docker compose ps
|
ansible.builtin.command: docker compose ps
|
||||||
@@ -117,6 +140,8 @@
|
|||||||
chdir: "{{ netbird_dir }}"
|
chdir: "{{ netbird_dir }}"
|
||||||
register: compose_ps
|
register: compose_ps
|
||||||
changed_when: false
|
changed_when: false
|
||||||
|
tags:
|
||||||
|
- config
|
||||||
|
|
||||||
- name: Дождаться ответа панели
|
- name: Дождаться ответа панели
|
||||||
ansible.builtin.command: >
|
ansible.builtin.command: >
|
||||||
@@ -128,7 +153,11 @@
|
|||||||
retries: 30
|
retries: 30
|
||||||
delay: 10
|
delay: 10
|
||||||
until: panel_http.stdout in ['200', '302']
|
until: panel_http.stdout in ['200', '302']
|
||||||
|
tags:
|
||||||
|
- config
|
||||||
|
|
||||||
- name: Итог установки
|
- name: Итог установки
|
||||||
ansible.builtin.debug:
|
ansible.builtin.debug:
|
||||||
msg: "{{ compose_ps.stdout_lines + ['Первый вход: https://' + netbird_domain + '/setup'] }}"
|
msg: "{{ compose_ps.stdout_lines + ['Первый вход: https://' + netbird_domain + '/setup'] }}"
|
||||||
|
tags:
|
||||||
|
- config
|
||||||
Reference in new issue
Block a user