40 lines
1.0 KiB
YAML
40 lines
1.0 KiB
YAML
---
|
|
- 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:
|
|
- name: Allow new SSH port in Windows Firewall
|
|
# Теперь можно писать короче, так как коллекции подключили выше
|
|
win_firewall_rule:
|
|
name: "OpenSSH-Server-Custom-Port"
|
|
localport: "{{ new_ssh_port }}"
|
|
action: allow
|
|
direction: in
|
|
protocol: tcp
|
|
profiles: domain,private,public
|
|
state: present
|
|
enabled: yes
|
|
|
|
- name: Update Port in sshd_config
|
|
win_lineinfile:
|
|
path: "{{ sshd_config_path }}"
|
|
regexp: '^#?Port\s+\d+'
|
|
line: "Port {{ new_ssh_port }}"
|
|
state: present
|
|
notify: Restart Windows SSH
|
|
|
|
handlers:
|
|
- name: Restart Windows SSH
|
|
win_service:
|
|
name: sshd
|
|
state: restarted |