Files
homelab-infra/ansible/roles/host/tasks/main.yml
T

92 lines
2.6 KiB
YAML

---
- name: Подготовить Python для Ansible
ansible.builtin.raw: DEBIAN_FRONTEND=noninteractive apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y python3 python3-apt
changed_when: false
- name: Собрать факты
ansible.builtin.setup:
- name: Создать каталог .ssh
ansible.builtin.file:
path: /root/.ssh
state: directory
owner: root
group: root
mode: "0700"
- name: Добавить авторизованные SSH-ключи
ansible.posix.authorized_key:
user: root
key: "{{ item }}"
state: present
loop: "{{ host_authorized_keys }}"
- name: Удалить cloud-init настройки пароля SSH
ansible.builtin.file:
path: /etc/ssh/sshd_config.d/50-cloud-init.conf
state: absent
notify: Перезапустить SSH
- name: Отключить вход по паролю в drop-in sshd_config.d
ansible.builtin.copy:
dest: /etc/ssh/sshd_config.d/00-disable-passwords.conf
content: |
PasswordAuthentication no
KbdInteractiveAuthentication no
owner: root
group: root
mode: "0644"
notify: Перезапустить SSH
- name: Удалить устаревший drop-in sshd_config.d
ansible.builtin.file:
path: /etc/ssh/sshd_config.d/99-disable-passwords.conf
state: absent
notify: Перезапустить SSH
- name: Запретить PasswordAuthentication в основном sshd_config
ansible.builtin.lineinfile:
path: /etc/ssh/sshd_config
regexp: '^(#\s*)?PasswordAuthentication\s+.*'
line: 'PasswordAuthentication no'
notify: Перезапустить SSH
- name: Применить настройки SSH
ansible.builtin.meta: flush_handlers
- name: Поставить Docker
ansible.builtin.apt:
name:
- docker.io
- docker-compose
- ufw
- ca-certificates
- curl
state: present
update_cache: true
- name: Включить Docker
ansible.builtin.systemd:
name: docker
enabled: true
state: started
- name: Разрешить SSH
ansible.builtin.command: ufw allow OpenSSH
register: ufw_ssh
changed_when: "'added' in (ufw_ssh.stdout | lower)"
when: ansible_virtualization_type | default('') != 'lxc'
- name: Проверить состояние firewall
ansible.builtin.command: ufw status
register: ufw_status
changed_when: false
when: ansible_virtualization_type | default('') != 'lxc'
- name: Включить firewall
ansible.builtin.command: ufw --force enable
when:
- ansible_virtualization_type | default('') != 'lxc'
- "'Status: active' not in ufw_status.stdout"
changed_when: true