lancelot : modèle 9100 avec agent QEMU, machine-id régénéré, pool et destroy par l'API
- 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>
This commit is contained in:
1 parent
f315304849
commit
de23e19910
8 files changed
+106
-29
No files matched your search
@@ -0,0 +1,48 @@
|
||||
---
|
||||
# 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
|
||||
@@ -7,6 +7,11 @@
|
||||
fail_msg: "Exportez PVE_TOKEN_SECRET (jeton {{ pve_api_user }}!{{ pve_api_token_id }}) ou PROXMOX_CLAUDE et PROXMOX_PASSWORD"
|
||||
quiet: true
|
||||
|
||||
- name: Créer le pool {{ pve_pool }}
|
||||
community.proxmox.proxmox_pool:
|
||||
poolid: "{{ pve_pool }}"
|
||||
comment: PoC BunkerWeb
|
||||
|
||||
- name: Créer le répertoire des host_vars par VM
|
||||
ansible.builtin.file:
|
||||
path: "{{ inventory_dir }}/host_vars/{{ item }}"
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
---
|
||||
- name: "{{ vm_name }} : lecture des paramètres"
|
||||
ansible.builtin.set_fact:
|
||||
vm: "{{ hostvars[vm_name] }}"
|
||||
# Uniquement les champs utiles : copier tout hostvars[vm] échoue avec ansible-core 2.21
|
||||
vm:
|
||||
vm_id: "{{ hostvars[vm_name].vm_id }}"
|
||||
vm_cores: "{{ hostvars[vm_name].vm_cores }}"
|
||||
vm_memory: "{{ hostvars[vm_name].vm_memory }}"
|
||||
vm_disk_gb: "{{ hostvars[vm_name].vm_disk_gb }}"
|
||||
|
||||
- name: "{{ vm_name }} : la VM existe-t-elle ?"
|
||||
community.proxmox.proxmox_vm_info:
|
||||
@@ -54,6 +59,11 @@
|
||||
state: started
|
||||
timeout: 120
|
||||
|
||||
# Un clone hérite du machine-id du modèle : systemd-networkd en dérive son identifiant
|
||||
# DHCP, et toutes les VM recevraient la même IP. On le régénère une fois (marqueur /etc/bwpoc-machine-id).
|
||||
- name: "{{ vm_name }} : nouveau machine-id (identifiant DHCP propre)"
|
||||
ansible.builtin.include_tasks: machine_id.yml
|
||||
|
||||
- name: "{{ vm_name }} : adresse DHCP remontée par l'agent QEMU"
|
||||
community.proxmox.proxmox_vm_info:
|
||||
node: "{{ pve_node }}"
|
||||
|
||||
Reference in new issue
Block a user