iac/ansible/roles/xmpp_cert_sync/tasks/main.yaml
Sergei Poljanski ffb81b4523
ansible: hand asxpio-services over to NixOS
asxpio-services moves to NixOS (branch nix). Without this, the next
deploy from main would apply the Debian roles to it. Take it out of
every play: services_servers is empty, and the host stays in the
inventory only so that ops's roles can still read its addresses and
public IP. The xmpp_cert_sync tasks that set up the receiving end on
services through delegate_to now run only while services is managed
here; on NixOS that end is part of its configuration.

A dry run of site.yaml against production with this change: ops ok=62
changed=0, every services play skipped.

Assisted-by: Claude:opus-5-5
2026-11-17 06:00:51 +04:00

63 lines
2 KiB
YAML

---
# Runs on asxpio-ops (where Traefik keeps the certificate); sets up the
# receiving end on asxpio-services through delegate_to.
- name: Generate the sync SSH key
community.crypto.openssh_keypair:
path: /root/.ssh/xmpp_cert_sync
type: ed25519
comment: xmpp-cert-sync@{{ inventory_hostname }}
register: xmpp_cert_sync_key
# The receiving end is set up here only while services is managed by
# Ansible; on NixOS it is part of nixos/hosts/asxpio-services, which
# authorizes this host's existing key until ops converts too.
- name: Install the receiving script on asxpio-services
ansible.builtin.copy:
src: xmpp-cert-install
dest: /usr/local/bin/xmpp-cert-install
mode: "0755"
delegate_to: asxpio-services
when: "'asxpio-services' in groups['services_servers'] | default([])"
- name: Authorize the key for that script only, from ops only
ansible.posix.authorized_key:
user: root
key: "{{ xmpp_cert_sync_key.public_key }}"
key_options: 'restrict,from="{{ asxpio_ops_vpc_ip }}",command="/usr/local/bin/xmpp-cert-install"'
comment: xmpp-cert-sync
delegate_to: asxpio-services
# In a dry run on a fresh host the key does not exist yet
when:
- xmpp_cert_sync_key.public_key is defined
- "'asxpio-services' in groups['services_servers'] | default([])"
- name: Install the sync script
ansible.builtin.template:
src: xmpp-cert-sync.j2
dest: /usr/local/bin/xmpp-cert-sync
mode: "0755"
- name: Install the sync units
ansible.builtin.copy:
src: "{{ item }}"
dest: "/etc/systemd/system/{{ item }}"
mode: "0644"
loop:
- xmpp-cert-sync.service
- xmpp-cert-sync.path
- xmpp-cert-sync.timer
notify: Reload systemd
- name: Flush handlers
ansible.builtin.meta: flush_handlers
- name: Enable the path watch and the daily fallback
ansible.builtin.systemd:
name: "{{ item }}"
enabled: true
state: started
loop:
- xmpp-cert-sync.path
- xmpp-cert-sync.timer
# A dry run installs no new unit files
ignore_errors: "{{ ansible_check_mode }}"