From 69e098415bec3a4ec5794b6c467ecc441e565057 Mon Sep 17 00:00:00 2001 From: karpenok Date: Sun, 8 Nov 2026 12:38:02 +0700 Subject: [PATCH] =?UTF-8?q?refactor:=20=D0=BF=D0=B5=D1=80=D0=B5=D0=B9?= =?UTF-8?q?=D1=82=D0=B8=20=D0=BD=D0=B0=20ansible.posix.authorized=5Fkey,?= =?UTF-8?q?=20=D0=BE=D1=87=D0=B8=D1=89=D0=B0=D1=82=D1=8C=20=D0=BA=D0=BB?= =?UTF-8?q?=D1=8E=D1=87=20=D1=80=D0=B0=D0=BD=D0=BD=D0=B5=D1=80=D0=B0=20?= =?UTF-8?q?=D0=B8=20=D0=BF=D0=BE=D0=B4=D0=B4=D0=B5=D1=80=D0=B6=D0=B0=D1=82?= =?UTF-8?q?=D1=8C=20=D0=B2=D0=BD=D0=B5=D1=88=D0=BD=D0=B8=D0=B5=20=D1=81?= =?UTF-8?q?=D0=B5=D0=BA=D1=80=D0=B5=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/netbird-install.yml | 2 ++ requirements.yml | 3 +++ roles/host/tasks/main.yml | 10 +++------- roles/netbird/tasks/main.yml | 8 ++++---- 4 files changed, 12 insertions(+), 11 deletions(-) create mode 100644 requirements.yml diff --git a/.gitea/workflows/netbird-install.yml b/.gitea/workflows/netbird-install.yml index 723d741..01f3735 100644 --- a/.gitea/workflows/netbird-install.yml +++ b/.gitea/workflows/netbird-install.yml @@ -47,8 +47,10 @@ jobs: install -d -m 700 "${HOME}/.ssh" printf '%s\n' "${RUNNER_SSH_KEY}" > "${HOME}/.ssh/id_ed25519" chmod 600 "${HOME}/.ssh/id_ed25519" + trap 'rm -f "${HOME}/.ssh/id_ed25519"' EXIT cd "${HOME}/homelab-infra" + ansible-galaxy collection install -r requirements.yml ansible-playbook playbooks/site.yml \ -i inventories/prod/hosts.yml \ diff --git a/requirements.yml b/requirements.yml new file mode 100644 index 0000000..a0cd255 --- /dev/null +++ b/requirements.yml @@ -0,0 +1,3 @@ +--- +collections: + - name: ansible.posix diff --git a/roles/host/tasks/main.yml b/roles/host/tasks/main.yml index 74c33d1..7811dee 100644 --- a/roles/host/tasks/main.yml +++ b/roles/host/tasks/main.yml @@ -15,14 +15,10 @@ mode: "0700" - name: Добавить авторизованные SSH-ключи - ansible.builtin.lineinfile: - path: /root/.ssh/authorized_keys - line: "{{ item }}" + ansible.posix.authorized_key: + user: root + key: "{{ item }}" state: present - create: true - owner: root - group: root - mode: "0600" loop: "{{ host_authorized_keys }}" - name: Удалить cloud-init настройки пароля SSH diff --git a/roles/netbird/tasks/main.yml b/roles/netbird/tasks/main.yml index 098ba2e..11562a3 100644 --- a/roles/netbird/tasks/main.yml +++ b/roles/netbird/tasks/main.yml @@ -42,7 +42,7 @@ - auth - datastore - session - when: not netbird_env.stat.exists + when: not netbird_env.stat.exists and netbird_auth_secret is not defined - name: Запомнить новые ключи ansible.builtin.set_fact: @@ -50,14 +50,14 @@ netbird_datastore_key: "{{ netbird_generated_keys.results[1].stdout }}" netbird_session_key: "{{ netbird_generated_keys.results[2].stdout }}" no_log: true - when: not netbird_env.stat.exists + when: not netbird_env.stat.exists and netbird_auth_secret is not defined - name: Прочитать сохранённые ключи ansible.builtin.slurp: src: "{{ netbird_dir }}/.env" register: netbird_env_raw no_log: true - when: netbird_env.stat.exists + when: netbird_env.stat.exists and netbird_auth_secret is not defined tags: - config @@ -71,7 +71,7 @@ env_lines: "{{ (netbird_env_raw.content | b64decode).splitlines() | reject('equalto', '') | list }}" env_map: "{{ dict(env_lines | map('split', '=', 1)) }}" no_log: true - when: netbird_env.stat.exists + when: netbird_env.stat.exists and netbird_auth_secret is not defined tags: - config