Files
infra/ansible/roles/bootstrap/tasks/main.yml
T
Dmitry dc3ff78d6d
Deploy cloud-pc / deploy (push) Failing after 15s
Deploy mini-pc / deploy (push) Failing after 4s
Deploy ru-vps / deploy (push) Failing after 5s
Refactor Docker Compose configurations and add deployment workflows for cloud-pc and mini-pc services
2026-05-27 15:41:15 +03:00

61 lines
2.2 KiB
YAML

- name: Ensure user exists
ansible.builtin.user:
name: "{{ bootstrap_user }}"
shell: /bin/bash
groups: sudo
append: true
create_home: true
state: present
# docker group создаётся только после установки Docker.
# Добавление происходит в роли docker, не здесь.
- name: Add SSH authorized keys
ansible.posix.authorized_key:
user: "{{ bootstrap_user }}"
key: "{{ item }}"
state: present
loop: "{{ bootstrap_ssh_public_keys }}"
when: bootstrap_ssh_public_keys | length > 0
# Команды, которые реально нужны без пароля:
# apt / apt-get — обновление пакетов
# systemctl — управление сервисами
# ufw — фаервол
# resticprofile — установка systemd-таймеров бэкапа
#
# Ansible become НЕ входит в этот список намеренно:
# для плейбуков запускать с -K. Это сознательный компромисс
# между удобством и тем, чтобы не давать python3 NOPASSWD (= root).
- name: Configure sudoers — NOPASSWD for specific commands
ansible.builtin.copy:
dest: /etc/sudoers.d/{{ bootstrap_user }}
content: |
{{ bootstrap_user }} ALL=(ALL) NOPASSWD: /usr/bin/apt, /usr/bin/apt-get
{{ bootstrap_user }} ALL=(ALL) NOPASSWD: /usr/bin/systemctl
{{ bootstrap_user }} ALL=(ALL) NOPASSWD: /usr/bin/ufw
{{ bootstrap_user }} ALL=(ALL) NOPASSWD: /usr/local/bin/resticprofile
validate: /usr/sbin/visudo -cf %s
mode: "0440"
# Drop-in конфиг — не трогаем основной sshd_config.
# Требует Debian 12+ (OpenSSH 8.9+).
- name: Harden SSH
ansible.builtin.copy:
dest: /etc/ssh/sshd_config.d/99-hardening.conf
content: |
PasswordAuthentication no
PermitRootLogin no
PubkeyAuthentication yes
mode: "0644"
notify: restart sshd
- name: Ensure sshd_config.d is included
ansible.builtin.lineinfile:
path: /etc/ssh/sshd_config
line: Include /etc/ssh/sshd_config.d/*.conf
state: present
insertbefore: BOF
validate: /usr/sbin/sshd -t -f %s
notify: restart sshd