--- - 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.builtin.lineinfile: path: /root/.ssh/authorized_keys line: "{{ item }}" state: present create: true owner: root group: root mode: "0600" 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: Поставить Docker ansible.builtin.apt: name: - docker.io - docker-compose-v2 - 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)" - name: Проверить состояние firewall ansible.builtin.command: ufw status register: ufw_status changed_when: false - name: Включить firewall ansible.builtin.command: ufw --force enable when: "'Status: active' not in ufw_status.stdout" changed_when: true