Files
ansible-repo/playbooks/ssh-certs/deploy-host-certs.yml
hogweed1 5d2a9e4a2e
All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 0s
ssh-certs hosts.
2026-05-22 01:31:56 +10:00

90 lines
4.0 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

- hosts: all
become: yes
vars:
# Имя провижнера на сервере step-ca, который имеет право подписывать хосты
step_host_provisioner: "ssh-host-provisioner"
# Путь к файлу с паролем от этого провижнера на вашей Ansible-машине
step_provisioner_password_file: "/etc/step-ca/host_provisioner_password.txt"
tasks:
- name: Создание временной папки на Ansible-машине для генерации ключей хоста
delegate_to: localhost
become: no
file:
path: "/tmp/ssh_host_certs/{{ inventory_hostname }}"
state: directory
mode: '0755'
- name: Локальная генерация временной пары ключей на Ansible-машине
delegate_to: localhost
become: no
openssh_keypair:
path: "/tmp/ssh_host_certs/{{ inventory_hostname }}/ssh_host_ed25519_key"
type: ed25519
state: present
- name: Удаленный выпуск Хост-сертификата силами step-ca
delegate_to: localhost
become: no
shell: >
step ssh certificate {{ inventory_hostname }} /tmp/ssh_host_certs/{{ inventory_hostname }}/ssh_host_ed25519_key.pub
--host --sign --provisioner "{{ step_host_provisioner }}"
--password-file "{{ step_provisioner_password_file }}"
--ca-url root-ca.guaranteedstruggle.host --root /usr/local/share/ca-certificates/pmc314_root-ca.crt
--principal "{{ inventory_hostname }}" --principal "{{ ansible_host }}"
--force
# step создаст два файла: сам публичный ключ и файл сертификата с суффиксом -cert.pub
# Нам нужно забрать получившийся сертификат и положить его на целевую ноду
- name: Копирование сгенерированного ЗАКРЫТОГО ключа хоста на целевую виртуалку
copy:
src: "/tmp/ssh_host_certs/{{ inventory_hostname }}/ssh_host_ed25519_key"
dest: /etc/ssh/ssh_host_ed25519_key
owner: root
group: root
mode: '0600' # Закрытый ключ должен быть строго 0600
- name: Копирование сгенерированного Хост-сертификата на целевую виртуалку
copy:
src: "/tmp/ssh_host_certs/{{ inventory_hostname }}/ssh_host_ed25519_key-cert.pub"
dest: /etc/ssh/ssh_host_ed25519_key-cert.pub
owner: root
group: root
mode: '0640' # Сертификат может быть 0640
- name: Настройка sshd_config для отдачи Хост-сертификата клиентам
blockinfile:
path: /etc/ssh/sshd_config
block: |
HostKey /etc/ssh/ssh_host_ed25519_key
HostCertificate /etc/ssh/ssh_host_ed25519_key-cert.pub
marker: "# {mark} ANSIBLE MANAGED HOST CERTIFICATE BLOCK #"
notify: Restart SSH
- name: Configure SSH HostKeys for Proxmox compatibility
blockinfile:
path: /etc/ssh/sshd_config # Или укажите путь к дроп-ину в sshd_config.d/, если используете их
block: |
# Coexistence with Proxmox internal clustering (Plain Keys fallback)
HostKey /etc/ssh/ssh_host_rsa_key
marker: "# {mark} ANSIBLE MANAGED HOST CERTIFICATE BLOCK #"
create: true
mode: '0600'
validate: /usr/sbin/sshd -t -f %s
when: "'proxmoxes' in group_names"
notify: Restart SSH
- name: Очистка временных файлов на Ansible-машине
delegate_to: localhost
become: no
file:
path: "/tmp/ssh_host_certs/{{ inventory_hostname }}"
state: absent
handlers:
- name: Restart SSH
service:
name: sshd
state: restarted