- modèle par défaut 9100 debian13-bwpoc (dérivé de 9001 + qemu-guest-agent), fabrication en SSH root seulement si pve_template_create: true - régénération du machine-id par l'agent QEMU (sinon même IP DHCP pour tous les clones) - pool bwpoc créé par l'API, 99-destroy par l'API - correctif ansible-core 2.21 (copie de hostvars), clé SSH id_ed25519 ou id_rsa Déploiement validé sur lancelot : 50-tests 26 OK, 0 KO. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
49 lines
1.9 KiB
YAML
49 lines
1.9 KiB
YAML
---
|
|
# Exécution dans la VM par l'agent QEMU (API /agent/exec), sans SSH.
|
|
- name: "{{ vm_name }} : authentification à l'API"
|
|
ansible.builtin.uri:
|
|
url: "https://{{ ansible_host }}:8006/api2/json/access/ticket"
|
|
method: POST
|
|
body_format: form-urlencoded
|
|
body:
|
|
username: "{{ pve_api_user }}"
|
|
password: "{{ pve_api_password }}"
|
|
validate_certs: "{{ pve_validate_certs }}"
|
|
register: pve_ticket
|
|
no_log: true
|
|
when: pve_api_token_secret | length == 0
|
|
|
|
- name: "{{ vm_name }} : en-têtes d'API"
|
|
ansible.builtin.set_fact:
|
|
pve_headers: >-
|
|
{{ {'Authorization': 'PVEAPIToken=' ~ pve_api_user ~ '!' ~ pve_api_token_id ~ '=' ~ pve_api_token_secret}
|
|
if pve_api_token_secret | length > 0 else
|
|
{'Cookie': 'PVEAuthCookie=' ~ pve_ticket.json.data.ticket,
|
|
'CSRFPreventionToken': pve_ticket.json.data.CSRFPreventionToken} }}
|
|
no_log: true
|
|
|
|
- name: "{{ vm_name }} : attente de l'agent QEMU"
|
|
ansible.builtin.uri:
|
|
url: "https://{{ ansible_host }}:8006/api2/json/nodes/{{ pve_node }}/qemu/{{ vm.vm_id }}/agent/ping"
|
|
method: POST
|
|
headers: "{{ pve_headers }}"
|
|
validate_certs: "{{ pve_validate_certs }}"
|
|
register: agent_ping
|
|
until: agent_ping.status == 200
|
|
retries: 60 # premier démarrage cloud-init : jusqu'à 5 min
|
|
delay: 5
|
|
|
|
- name: "{{ vm_name }} : régénérer le machine-id puis redémarrer"
|
|
ansible.builtin.uri:
|
|
url: "https://{{ ansible_host }}:8006/api2/json/nodes/{{ pve_node }}/qemu/{{ vm.vm_id }}/agent/exec"
|
|
method: POST
|
|
headers: "{{ pve_headers }}"
|
|
body_format: json
|
|
body:
|
|
command: ["sh", "-c", "test -f /etc/bwpoc-machine-id || { rm -f /etc/machine-id /var/lib/dbus/machine-id && systemd-machine-id-setup && touch /etc/bwpoc-machine-id && systemctl reboot; }"]
|
|
validate_certs: "{{ pve_validate_certs }}"
|
|
|
|
- name: "{{ vm_name }} : laisser le redémarrage commencer"
|
|
ansible.builtin.pause:
|
|
seconds: 20
|