Обновить test-playbooks/change_ssh_port_win.yml
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user