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