From 0d19f80039b33a7eeae98d54ad34815b11d92b70 Mon Sep 17 00:00:00 2001 From: karpenok Date: Sun, 8 Nov 2026 12:10:18 +0700 Subject: [PATCH] =?UTF-8?q?feat(host):=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2?= =?UTF-8?q?=D0=B8=D1=82=D1=8C=20=D0=BA=D0=BB=D1=8E=D1=87=D0=B8=20root=5Fho?= =?UTF-8?q?me=20=D0=B8=20=D1=80=D0=B0=D0=BD=D0=BD=D0=B5=D1=80=D0=B0,=20?= =?UTF-8?q?=D0=BE=D1=82=D0=BA=D0=BB=D1=8E=D1=87=D0=B8=D1=82=D1=8C=20=D0=B2?= =?UTF-8?q?=D1=85=D0=BE=D0=B4=20=D0=BF=D0=BE=20=D0=BF=D0=B0=D1=80=D0=BE?= =?UTF-8?q?=D0=BB=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/netbird-install.yml | 4 +-- inventories/prod/hosts.yml | 1 + roles/host/defaults/main.yml | 4 +++ roles/host/handlers/main.yml | 5 ++++ roles/host/tasks/main.yml | 37 ++++++++++++++++++++++++++++ 5 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 roles/host/defaults/main.yml create mode 100644 roles/host/handlers/main.yml diff --git a/.gitea/workflows/netbird-install.yml b/.gitea/workflows/netbird-install.yml index 68ed1d4..723d741 100644 --- a/.gitea/workflows/netbird-install.yml +++ b/.gitea/workflows/netbird-install.yml @@ -30,10 +30,10 @@ jobs: if [ "$(id -u)" -eq 0 ]; then apt-get update - apt-get install -y git openssh-client ansible-core python3 + apt-get install -y git openssh-client ansible-core python3 sshpass else sudo apt-get update - sudo apt-get install -y git openssh-client ansible-core python3 + sudo apt-get install -y git openssh-client ansible-core python3 sshpass fi rm -rf "${HOME}/homelab-infra" diff --git a/inventories/prod/hosts.yml b/inventories/prod/hosts.yml index 8f03614..af22a71 100644 --- a/inventories/prod/hosts.yml +++ b/inventories/prod/hosts.yml @@ -7,6 +7,7 @@ all: rus-central: ansible_host: 45.154.185.208 ansible_user: root + ansible_password: "rJ1vC5cS5gxA" netbird: hosts: rus-central: diff --git a/roles/host/defaults/main.yml b/roles/host/defaults/main.yml new file mode 100644 index 0000000..604464a --- /dev/null +++ b/roles/host/defaults/main.yml @@ -0,0 +1,4 @@ +--- +host_authorized_keys: + - "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIF/yxhAs022l/8FlPlhyi7NeF3CvVGsev3B1HtKICO7M root_from_windows" + - "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAICf80si9YG5lZkhRkVZUclrxu6hEGimWrAH/uib10rdi gitea@gitea" diff --git a/roles/host/handlers/main.yml b/roles/host/handlers/main.yml new file mode 100644 index 0000000..7f76425 --- /dev/null +++ b/roles/host/handlers/main.yml @@ -0,0 +1,5 @@ +--- +- name: Перезапустить SSH + ansible.builtin.service: + name: ssh + state: reloaded diff --git a/roles/host/tasks/main.yml b/roles/host/tasks/main.yml index d65fd40..e0cf861 100644 --- a/roles/host/tasks/main.yml +++ b/roles/host/tasks/main.yml @@ -6,6 +6,43 @@ - name: Собрать факты ansible.builtin.setup: +- name: Создать каталог .ssh + ansible.builtin.file: + path: /root/.ssh + state: directory + owner: root + group: root + mode: "0700" + +- name: Добавить авторизованные SSH-ключи + ansible.builtin.lineinfile: + path: /root/.ssh/authorized_keys + line: "{{ item }}" + state: present + create: true + owner: root + group: root + mode: "0600" + loop: "{{ host_authorized_keys }}" + +- name: Отключить вход по паролю в drop-in sshd_config.d + ansible.builtin.copy: + dest: /etc/ssh/sshd_config.d/99-disable-passwords.conf + content: | + PasswordAuthentication no + KbdInteractiveAuthentication no + owner: root + group: root + mode: "0644" + notify: Перезапустить SSH + +- name: Запретить PasswordAuthentication в основном sshd_config + ansible.builtin.lineinfile: + path: /etc/ssh/sshd_config + regexp: '^(#\s*)?PasswordAuthentication\s+.*' + line: 'PasswordAuthentication no' + notify: Перезапустить SSH + - name: Поставить Docker ansible.builtin.apt: name: