From 2122824b6d554721f8beb61fbc399935d4d510ef Mon Sep 17 00:00:00 2001 From: ogrechko Date: Fri, 5 Dec 2025 09:08:46 +0000 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=B8=D1=82?= =?UTF-8?q?=D1=8C=20test-playbooks/change=5Fssh=5Fport=5Fwin.yml?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test-playbooks/change_ssh_port_win.yml | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/test-playbooks/change_ssh_port_win.yml b/test-playbooks/change_ssh_port_win.yml index eba20b3..9b2d2ef 100644 --- a/test-playbooks/change_ssh_port_win.yml +++ b/test-playbooks/change_ssh_port_win.yml @@ -2,15 +2,20 @@ - name: Change SSH Port on Windows hosts: windows gather_facts: no + + # ДОБАВИТЬ ЭТОТ БЛОК: + collections: + - ansible.windows + - community.windows + vars: new_ssh_port: 22233 sshd_config_path: 'C:\ProgramData\ssh\sshd_config' tasks: - # 1. Открываем порт в Windows Firewall (Defender) - # Делаем это первым делом, чтобы не потерять доступ после рестарта - name: Allow new SSH port in Windows Firewall - community.windows.win_firewall_rule: + # Теперь можно писать короче, так как коллекции подключили выше + win_firewall_rule: name: "OpenSSH-Server-Custom-Port" localport: "{{ new_ssh_port }}" action: allow @@ -20,10 +25,8 @@ state: present enabled: yes - # 2. Меняем порт в конфиге sshd_config - # Ищет строку "Port 22" или "#Port 22" и меняет на новый порт - name: Update Port in sshd_config - ansible.windows.win_lineinfile: + win_lineinfile: path: "{{ sshd_config_path }}" regexp: '^#?Port\s+\d+' line: "Port {{ new_ssh_port }}" @@ -32,6 +35,6 @@ handlers: - name: Restart Windows SSH - ansible.windows.win_service: + win_service: name: sshd state: restarted \ No newline at end of file