Updated README for all rolers, added role for configure sshd_config

pull/2/head
yuobrezkov 2025-01-31 15:27:31 +03:00
parent 5822cdc7e0
commit a758261414
9 changed files with 117 additions and 0 deletions

0
ssh/README.md Normal file
View File

View File

@ -0,0 +1,37 @@
# Роль Ansible: Настройка SSH
## Описание
Данная роль предназначена для настройки сервера SSH на удалённых хостах с помощью Ansible. Она выполняет следующие задачи:
1. Гарантирует, что каталог `/etc/ssh` существует и имеет правильные права доступа.
2. Настраивает параметры SSH-сервера в файле `sshd_config`.
3. Включает и запускает службу `sshd`.
4. При изменении конфигурации SSH перезапускает службу `sshd`.
## Требования
Роль не требует дополнительных зависимостей, кроме установленного Ansible и наличия прав суперпользователя на целевых хостах.
## Переменные роли
Роль не использует внешние переменные и работает с фиксированными параметрами SSH.
## Зависимости
Зависимости от других ролей отсутствуют.
## Пример Playbook
Пример использования роли в Playbook:
```yaml
- hosts: servers
become: yes
roles:
- ssh_config_role
```
## Автор
Автор: [Юрий Обрезков]

View File

@ -0,0 +1,5 @@
---
- name: Restart SSH
service:
name: sshd
state: restarted

View File

@ -0,0 +1,34 @@
galaxy_info:
author: your name
description: your role description
company: your company (optional)
# If the issue tracker for your role is not on github, uncomment the
# next line and provide a value
# issue_tracker_url: http://example.com/issue/tracker
# Choose a valid license ID from https://spdx.org - some suggested licenses:
# - BSD-3-Clause (default)
# - MIT
# - GPL-2.0-or-later
# - GPL-3.0-only
# - Apache-2.0
# - CC-BY-4.0
license: license (GPL-2.0-or-later, MIT, etc)
min_ansible_version: 2.1
# If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version:
galaxy_tags: []
# List tags for your role here, one per line. A tag is a keyword that describes
# and categorizes the role. Users find roles by searching for tags. Be sure to
# remove the '[]' above, if you add tags to this list.
#
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
# Maximum 20 tags per role.
dependencies: []
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
# if you add dependencies to this list.

View File

@ -0,0 +1,26 @@
- name: Ensure SSH directory exists
file:
path: /etc/ssh
state: directory
mode: '0755'
- name: Configure SSH server
lineinfile:
path: /etc/ssh/sshd_config
regexp: "^{{ item.key }}"
line: "{{ item.key }} {{ item.value }}"
create: yes
state: present
loop:
- { key: "Port", value: "22" }
- { key: "PubkeyAuthentication", value: "yes" }
- { key: "X11Forwarding", value: "yes" }
- { key: "PrintMotd", value: "no" }
- { key: "UsePAM", value: "yes" }
notify: Restart SSH
- name: Ensure SSH service is enabled and running
service:
name: sshd
state: started
enabled: yes

View File

@ -0,0 +1,2 @@
localhost

View File

@ -0,0 +1,5 @@
---
- hosts: localhost
remote_user: root
roles:
- ssh_setup

View File

@ -0,0 +1,2 @@
---
# vars file for ssh

6
ssh/ssh_setup_config.yml Normal file
View File

@ -0,0 +1,6 @@
- name: Update ssh config
become: yes
hosts: all
roles:
- role: ssh_setup
tags: ssh_setup