Regroupement de la chaîne de tests de charge beWeapon
- template/ : build Packer du template Windows 11 (ex /data/Installer/MyTemplate) - deploy/ : OpenTofu + playbooks Ansible (ex /data/Tofu) - bin/Deploy : menu de déploiement (lien depuis /usr/local/bin/Deploy) - jeton API Proxmox sorti des playbooks vers deploy/proxmox-secret.yml (hors git) - README.md : documentation de la structure et du mode opératoire - Ameliorations.md : recommandations pour fiabiliser les mesures - tests/ (dépôt beWeapon-LT) et archives/ exclus Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f1eeba20c4
commit
1e2bcf21cf
40 files changed
+3498
No files matched your search
Generated
+24
@@ -0,0 +1,24 @@
|
||||
# This file is maintained automatically by "tofu init".
|
||||
# Manual edits may be lost in future updates.
|
||||
|
||||
provider "registry.opentofu.org/bpg/proxmox" {
|
||||
version = "0.107.0"
|
||||
constraints = ">= 0.50.0"
|
||||
hashes = [
|
||||
"h1:W/DuNEQCgP510F1LfeRCvJa4vXGNT2byH7DzbknpEO4=",
|
||||
"zh:3c1e298f4f0d954e83d11aaf2400ec242b835ca294f8a94d67bb5ce0b30da0e9",
|
||||
"zh:4776f7f262728f8e2252360f7d1a4adc853d87d86a7515f4780375c2932ef763",
|
||||
"zh:53633a48f7fad5561a30b349e7b46c6a7a10a54c99225a4d30a7a24086921098",
|
||||
"zh:62686df322f773b40c1881eb7932058cbf68101bfa5cd66bc08c9bcb6ad0bdfd",
|
||||
"zh:62afd9992f9089311a876c7e79d35a8b7935c0c553f6de8fb6ac2b76f5c4a3ce",
|
||||
"zh:6b379f3858ba8bd548b7d50c07f7fb7eb339d2020c07c2b69aaba1f2247aedae",
|
||||
"zh:8a520d7df039cb060182683d823d1705423cd9e97936b8e65a27dbf54ea9643a",
|
||||
"zh:b489993495332d3d4aedfd53a7ff80ce880a58ec575bf3340646791c1803862c",
|
||||
"zh:db164bc934aaeb56ae1b368208c7cd33f5af5ac84dc98fa7da736a62a5ede143",
|
||||
"zh:eeb9611c160baf65e6acede202b9d923d185395af2725425c2f8226403675155",
|
||||
"zh:f24b8014a513483cef883caf58884a380fb51567e50ea5425a3d5ec6629f4a9b",
|
||||
"zh:f26e0763dbe6a6b2195c94b44696f2110f7f55433dc142839be16b9697fa5597",
|
||||
"zh:f329a8f344ec11c64686a0b29cd706f5dfedb19925a58aa61fb39f0d0a854619",
|
||||
"zh:ff0a8a1ac74eaef2826054982d82cb42f1376dac98f3d30f995d60f4964ee7b1",
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
---
|
||||
- name: Récupération des IPs des VMs OpenTofu
|
||||
hosts: localhost
|
||||
connection: local
|
||||
gather_facts: false
|
||||
|
||||
tasks:
|
||||
- name: Récupérer les outputs OpenTofu
|
||||
command: tofu output -json vms_info
|
||||
register: tofu_output_raw
|
||||
|
||||
- name: Parser le JSON OpenTofu
|
||||
set_fact:
|
||||
vms_data: "{{ tofu_output_raw.stdout | from_json }}"
|
||||
|
||||
- name: Préparer la liste des données pour le CSV
|
||||
set_fact:
|
||||
vm_list: >-
|
||||
{%- set result = [] -%}
|
||||
{%- for name, details in vms_data.items() -%}
|
||||
{%- set ip = (details.ipv4_addresses | default([[]]))[1] | default(details.ipv4_addresses[0][0] | default('Non attribuée')) -%}
|
||||
{%- set _ = result.append({'name': name, 'id': details.id, 'ip': ip}) -%}
|
||||
{%- endfor -%}
|
||||
{{ result }}
|
||||
|
||||
- name: Afficher les IPs à l'écran
|
||||
debug:
|
||||
msg: "VM: {{ item.name }} (ID: {{ item.id }}) -> IP: {{ item.ip }}"
|
||||
loop: "{{ vm_list }}"
|
||||
|
||||
- name: Générer le fichier CSV machines_ip.csv
|
||||
copy:
|
||||
content: |
|
||||
Nom_VM,ID_Proxmox,Adresse_IP
|
||||
{% for vm in vm_list %}
|
||||
{{ vm.name }},{{ vm.id }},{{ vm.ip }}
|
||||
{% endfor %}
|
||||
dest: "./machines_ip.csv"
|
||||
@@ -0,0 +1,77 @@
|
||||
---
|
||||
- name: Orchestration Démarrage et IPs des VMs
|
||||
hosts: localhost
|
||||
connection: local
|
||||
gather_facts: false
|
||||
vars_files:
|
||||
- proxmox-secret.yml # secret hors git (voir proxmox-secret.yml.sample)
|
||||
|
||||
vars:
|
||||
ansible_python_interpreter: "/data/bin/python3"
|
||||
proxmox_api_host: "192.168.111.220" # Votre IP Proxmox
|
||||
proxmox_user: "root@pam"
|
||||
proxmox_token_id: "Stid"
|
||||
csv_file_path: "./machines_ip.csv"
|
||||
|
||||
tasks:
|
||||
- name: 1. Récupérer les données OpenTofu
|
||||
command: tofu output -json vms_info
|
||||
register: tofu_output_raw
|
||||
changed_when: false
|
||||
|
||||
- name: Extraire la liste des VMs
|
||||
set_fact:
|
||||
vms_dict: "{{ tofu_output_raw.stdout | from_json }}"
|
||||
|
||||
- name: 3. Interroger l'agent QEMU via l'API Proxmox pour récupérer l'IP
|
||||
uri:
|
||||
url: "https://{{ proxmox_api_host }}:8006/api2/json/nodes/{{ item.value.node }}/qemu/{{ item.value.id }}/agent/network-get-interfaces"
|
||||
method: GET
|
||||
headers:
|
||||
Authorization: "PVEAPIToken={{ proxmox_user }}!{{ proxmox_token_id }}={{ proxmox_token_secret }}"
|
||||
validate_certs: false
|
||||
status_code: [200]
|
||||
register: agent_net_info
|
||||
until:
|
||||
- agent_net_info.json is defined
|
||||
- agent_net_info.json.data.result is defined
|
||||
- (agent_net_info.json.data.result | map(attribute='ip-addresses', default=[]) | flatten | selectattr('ip-address-type', 'equalto', 'ipv4') | map(attribute='ip-address') | reject('equalto', '127.0.0.1') | list | length) > 0
|
||||
retries: 30
|
||||
delay: 5
|
||||
loop: "{{ vms_dict | dict2items }}"
|
||||
|
||||
- name: 4. Extraire et associer les IPs
|
||||
set_fact:
|
||||
final_vm_list: >-
|
||||
{%- set result = [] -%}
|
||||
{%- for res in agent_net_info.results -%}
|
||||
{%- set vm_id = res.item.value.id -%}
|
||||
{%- set vm_name = res.item.value.name -%}
|
||||
{%- set ifaces = res.json.data.result | default([]) -%}
|
||||
{%- set ips = [] -%}
|
||||
{%- for iface in ifaces -%}
|
||||
{%- set addrs = iface['ip-addresses'] | default([]) -%}
|
||||
{%- for addr in addrs -%}
|
||||
{%- if addr['ip-address-type'] == 'ipv4' and addr['ip-address'] != '127.0.0.1' -%}
|
||||
{%- set _ = ips.append(addr['ip-address']) -%}
|
||||
{%- endif -%}
|
||||
{%- endfor -%}
|
||||
{%- endfor -%}
|
||||
{%- set main_ip = ips[0] | default('Non attribuee') -%}
|
||||
{%- set _ = result.append({'name': vm_name, 'id': vm_id, 'ip': main_ip}) -%}
|
||||
{%- endfor -%}
|
||||
{{ result }}
|
||||
|
||||
- name: 5. Afficher les résultats à l'écran
|
||||
debug:
|
||||
msg: "VM {{ item.name }} (ID: {{ item.id }}) -> IP: {{ item.ip }}"
|
||||
loop: "{{ final_vm_list }}"
|
||||
|
||||
- name: 6. Générer le fichier CSV
|
||||
copy:
|
||||
content: |
|
||||
Nom_VM,ID_Proxmox,Adresse_IP
|
||||
{% for vm in final_vm_list %}
|
||||
{{ vm.name }},{{ vm.id }},{{ vm.ip }}
|
||||
{% endfor %}
|
||||
dest: "{{ csv_file_path }}"
|
||||
+107
@@ -0,0 +1,107 @@
|
||||
# Déploiement de VM Windows sur Proxmox avec Terraform
|
||||
|
||||
terraform {
|
||||
required_providers {
|
||||
proxmox = {
|
||||
source = "bpg/proxmox"
|
||||
version = ">= 0.50.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
provider "proxmox" {
|
||||
endpoint = var.proxmox_endpoint
|
||||
api_token = var.proxmox_token
|
||||
insecure = true
|
||||
}
|
||||
|
||||
variable "proxmox_token" {
|
||||
description = "Token d'accès"
|
||||
type = string
|
||||
sensitive = true
|
||||
}
|
||||
|
||||
variable "proxmox_endpoint" {
|
||||
description = "URL de l'API Proxmox (ex: https://192.168.100.220:8006/api2/json)"
|
||||
type = string
|
||||
}
|
||||
|
||||
#variable "proxmox_username" {
|
||||
# description = "Utilisateur Proxmox (ex: root@pam)"
|
||||
# type = string
|
||||
#}
|
||||
|
||||
#variable "proxmox_password" {
|
||||
# description = "Mot de passe Proxmox"
|
||||
# type = string
|
||||
# sensitive = true
|
||||
#}
|
||||
|
||||
variable "vm_count" {
|
||||
description = "Nombre de VM à déployer"
|
||||
type = number
|
||||
}
|
||||
|
||||
variable "vm_template" {
|
||||
description = "Nom du template Windows à cloner"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "vm_template_id" {
|
||||
description = "ID du template Windows à cloner"
|
||||
type = number
|
||||
}
|
||||
|
||||
resource "proxmox_virtual_environment_vm" "test" {
|
||||
count = var.vm_count
|
||||
name = "beWeapon-${count.index}"
|
||||
node_name = "pmx-002" # À adapter selon votre cluster
|
||||
vm_id = 400 + count.index
|
||||
started = false
|
||||
clone {
|
||||
vm_id = var.vm_template_id
|
||||
full = false
|
||||
}
|
||||
cpu {
|
||||
cores = 4
|
||||
type = "x86-64-v2-AES"
|
||||
}
|
||||
memory {
|
||||
dedicated = 6144
|
||||
}
|
||||
operating_system {
|
||||
type = "win10"
|
||||
}
|
||||
network_device {
|
||||
bridge = "vmbr2"
|
||||
model = "e1000"
|
||||
}
|
||||
disk {
|
||||
datastore_id = "PVE-Thin"
|
||||
size = 64
|
||||
interface = "scsi0"
|
||||
}
|
||||
agent {
|
||||
enabled = true
|
||||
}
|
||||
|
||||
timeout_clone = 1800
|
||||
# timeouts {
|
||||
# create = "60m"
|
||||
# update = "60m"
|
||||
# delete = "30m"
|
||||
# }
|
||||
|
||||
}
|
||||
|
||||
output "vms_info" {
|
||||
value = {
|
||||
for idx, vm in proxmox_virtual_environment_vm.test : vm.name => {
|
||||
id = vm.id
|
||||
name = vm.name
|
||||
node = vm.node_name
|
||||
ipv4_addresses = vm.ipv4_addresses
|
||||
}
|
||||
}
|
||||
description = "Informations sur les VMs déployées"
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
# Copier en proxmox-secret.yml et renseigner le secret du jeton API Proxmox root@pam!Stid
|
||||
proxmox_token_secret: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
||||
@@ -0,0 +1,89 @@
|
||||
---
|
||||
- name: Orchestration Démarrage et IPs des VMs
|
||||
hosts: localhost
|
||||
connection: local
|
||||
gather_facts: false
|
||||
vars_files:
|
||||
- proxmox-secret.yml # secret hors git (voir proxmox-secret.yml.sample)
|
||||
|
||||
vars:
|
||||
ansible_python_interpreter: "/data/bin/python3"
|
||||
proxmox_api_host: "192.168.111.220" # Votre IP Proxmox
|
||||
proxmox_user: "root@pam"
|
||||
proxmox_token_id: "Stid"
|
||||
csv_file_path: "./machines_ip.csv"
|
||||
|
||||
tasks:
|
||||
- name: 1. Récupérer les données OpenTofu
|
||||
command: tofu output -json vms_info
|
||||
register: tofu_output_raw
|
||||
changed_when: false
|
||||
|
||||
- name: Extraire la liste des VMs
|
||||
set_fact:
|
||||
vms_dict: "{{ tofu_output_raw.stdout | from_json }}"
|
||||
|
||||
- name: 2. Démarrer toutes les VMs sur Proxmox
|
||||
community.proxmox.proxmox_kvm:
|
||||
api_host: "{{ proxmox_api_host }}"
|
||||
api_user: "{{ proxmox_user }}"
|
||||
api_token_id: "{{ proxmox_token_id }}"
|
||||
api_token_secret: "{{ proxmox_token_secret }}"
|
||||
validate_certs: false
|
||||
vmid: "{{ item.value.id }}"
|
||||
node: "{{ item.value.node }}"
|
||||
state: started
|
||||
loop: "{{ vms_dict | dict2items }}"
|
||||
|
||||
- name: 3. Interroger l'agent QEMU via l'API Proxmox pour récupérer l'IP
|
||||
uri:
|
||||
url: "https://{{ proxmox_api_host }}:8006/api2/json/nodes/{{ item.value.node }}/qemu/{{ item.value.id }}/agent/network-get-interfaces"
|
||||
method: GET
|
||||
headers:
|
||||
Authorization: "PVEAPIToken={{ proxmox_user }}!{{ proxmox_token_id }}={{ proxmox_token_secret }}"
|
||||
validate_certs: false
|
||||
status_code: [200]
|
||||
register: agent_net_info
|
||||
until:
|
||||
- agent_net_info.json is defined
|
||||
- agent_net_info.json.data.result is defined
|
||||
- (agent_net_info.json.data.result | map(attribute='ip-addresses', default=[]) | flatten | selectattr('ip-address-type', 'equalto', 'ipv4') | map(attribute='ip-address') | reject('equalto', '127.0.0.1') | list | length) > 0
|
||||
retries: 30
|
||||
delay: 5
|
||||
loop: "{{ vms_dict | dict2items }}"
|
||||
|
||||
- name: 4. Extraire et associer les IPs
|
||||
set_fact:
|
||||
final_vm_list: >-
|
||||
{%- set result = [] -%}
|
||||
{%- for res in agent_net_info.results -%}
|
||||
{%- set vm_id = res.item.value.id -%}
|
||||
{%- set vm_name = res.item.value.name -%}
|
||||
{%- set ifaces = res.json.data.result | default([]) -%}
|
||||
{%- set ips = [] -%}
|
||||
{%- for iface in ifaces -%}
|
||||
{%- set addrs = iface['ip-addresses'] | default([]) -%}
|
||||
{%- for addr in addrs -%}
|
||||
{%- if addr['ip-address-type'] == 'ipv4' and addr['ip-address'] != '127.0.0.1' -%}
|
||||
{%- set _ = ips.append(addr['ip-address']) -%}
|
||||
{%- endif -%}
|
||||
{%- endfor -%}
|
||||
{%- endfor -%}
|
||||
{%- set main_ip = ips[0] | default('Non attribuee') -%}
|
||||
{%- set _ = result.append({'name': vm_name, 'id': vm_id, 'ip': main_ip}) -%}
|
||||
{%- endfor -%}
|
||||
{{ result }}
|
||||
|
||||
- name: 5. Afficher les résultats à l'écran
|
||||
debug:
|
||||
msg: "VM {{ item.name }} (ID: {{ item.id }}) -> IP: {{ item.ip }}"
|
||||
loop: "{{ final_vm_list }}"
|
||||
|
||||
- name: 6. Générer le fichier CSV
|
||||
copy:
|
||||
content: |
|
||||
Nom_VM,ID_Proxmox,Adresse_IP
|
||||
{% for vm in final_vm_list %}
|
||||
{{ vm.name }},{{ vm.id }},{{ vm.ip }}
|
||||
{% endfor %}
|
||||
dest: "{{ csv_file_path }}"
|
||||
@@ -0,0 +1,97 @@
|
||||
---
|
||||
- name: Orchestration Démarrage et IPs des VMs
|
||||
hosts: localhost
|
||||
connection: local
|
||||
gather_facts: false
|
||||
vars_files:
|
||||
- proxmox-secret.yml # secret hors git (voir proxmox-secret.yml.sample)
|
||||
|
||||
vars:
|
||||
proxmox_api_host: "192.168.111.220"
|
||||
proxmox_user: "root@pam"
|
||||
proxmox_token_id: "Stid"
|
||||
csv_file_path: "./machines_ip.csv"
|
||||
ansible_python_interpreter: "/data/bin/python3"
|
||||
|
||||
tasks:
|
||||
- name: 1. Récupérer les données OpenTofu
|
||||
command: tofu output -json vms_info
|
||||
register: tofu_output_raw
|
||||
changed_when: false
|
||||
|
||||
- name: Extraire la liste des VMs
|
||||
set_fact:
|
||||
vms_dict: "{{ tofu_output_raw.stdout | from_json }}"
|
||||
|
||||
- name: 2. Démarrer toutes les VMs sur Proxmox en parallèle
|
||||
community.proxmox.proxmox_kvm:
|
||||
api_host: "{{ proxmox_api_host }}"
|
||||
api_user: "{{ proxmox_user }}"
|
||||
api_token_id: "{{ proxmox_token_id }}"
|
||||
api_token_secret: "{{ proxmox_token_secret }}"
|
||||
validate_certs: false
|
||||
vmid: "{{ item.value.id }}"
|
||||
node: "{{ item.value.node }}"
|
||||
state: started
|
||||
loop: "{{ vms_dict | dict2items }}"
|
||||
async: 90
|
||||
poll: 0
|
||||
register: start_jobs
|
||||
|
||||
- name: Attendre le déclenchement complet des démarrages
|
||||
async_status:
|
||||
jid: "{{ item.ansible_job_id }}"
|
||||
loop: "{{ start_jobs.results }}"
|
||||
when: item.ansible_job_id is defined
|
||||
until: async_result.finished
|
||||
retries: 30
|
||||
delay: 2
|
||||
register: async_result
|
||||
|
||||
- name: 3. Récupérer les informations réseau via l'Agent QEMU
|
||||
community.proxmox.proxmox_vm_info:
|
||||
api_host: "{{ proxmox_api_host }}"
|
||||
api_user: "{{ proxmox_user }}"
|
||||
api_token_id: "{{ proxmox_token_id }}"
|
||||
api_token_secret: "{{ proxmox_token_secret }}"
|
||||
validate_certs: false
|
||||
vmid: "{{ item.value.id }}"
|
||||
register: vm_details
|
||||
loop: "{{ vms_dict | dict2items }}"
|
||||
|
||||
- name: 4. Construire la liste finale avec les adresses IPv4
|
||||
set_fact:
|
||||
final_vm_list: >-
|
||||
{%- set result = [] -%}
|
||||
{%- for res in vm_details.results -%}
|
||||
{%- set vm_id = res.item.value.id -%}
|
||||
{%- set vm_name = res.item.value.name -%}
|
||||
{%- set ifaces = res.proxmox_vms[0].network_interfaces | default([]) -%}
|
||||
{%- set ips = [] -%}
|
||||
{%- for iface in ifaces if iface.name != 'lo' -%}
|
||||
{%- for ip in iface.ip_addresses | default([]) -%}
|
||||
{%- if ip.address is defined and (ip.address.startswith('192.') or ip.address.startswith('10.')) -%}
|
||||
{%- set _ = ips.append(ip.address) -%}
|
||||
{%- elif ip is string and (ip.startswith('192.') or ip.startswith('10.')) -%}
|
||||
{%- set _ = ips.append(ip) -%}
|
||||
{%- endif -%}
|
||||
{%- for_end -%}
|
||||
{%- endfor -%}
|
||||
{%- set main_ip = ips[0] | default('Non attribuee') -%}
|
||||
{%- set _ = result.append({'name': vm_name, 'id': vm_id, 'ip': main_ip}) -%}
|
||||
{%- endfor -%}
|
||||
{{ result }}
|
||||
|
||||
- name: 5. Afficher les résultats à l'écran
|
||||
debug:
|
||||
msg: "VM {{ item.name }} (ID: {{ item.id }}) -> IP DHCP: {{ item.ip }}"
|
||||
loop: "{{ final_vm_list }}"
|
||||
|
||||
- name: 6. Écrire le fichier CSV
|
||||
copy:
|
||||
content: |
|
||||
Nom_VM,ID_Proxmox,Adresse_IP
|
||||
{% for vm in final_vm_list %}
|
||||
{{ vm.name }},{{ vm.id }},{{ vm.ip }}
|
||||
{% endfor %}
|
||||
dest: "{{ csv_file_path }}"
|
||||
@@ -0,0 +1,85 @@
|
||||
---
|
||||
- name: Orchestration Démarrage et IPs des VMs
|
||||
hosts: localhost
|
||||
connection: local
|
||||
gather_facts: false
|
||||
vars_files:
|
||||
- proxmox-secret.yml # secret hors git (voir proxmox-secret.yml.sample)
|
||||
|
||||
vars:
|
||||
proxmox_api_host: "192.168.111.220" # Votre nouvelle IP Proxmox
|
||||
proxmox_user: "root@pam"
|
||||
proxmox_token_id: "Stid"
|
||||
csv_file_path: "./machines_ip.csv"
|
||||
ansible_python_interpreter: "/data/bin/python3"
|
||||
|
||||
tasks:
|
||||
- name: 1. Récupérer les données OpenTofu
|
||||
command: tofu output -json vms_info
|
||||
register: tofu_output_raw
|
||||
changed_when: false
|
||||
|
||||
- name: Extraire la liste des VMs
|
||||
set_fact:
|
||||
vms_dict: "{{ tofu_output_raw.stdout | from_json }}"
|
||||
|
||||
- name: 2. Démarrer toutes les VMs sur Proxmox
|
||||
community.proxmox.proxmox_kvm:
|
||||
api_host: "{{ proxmox_api_host }}"
|
||||
api_user: "{{ proxmox_user }}"
|
||||
api_token_id: "{{ proxmox_token_id }}"
|
||||
api_token_secret: "{{ proxmox_token_secret }}"
|
||||
validate_certs: false
|
||||
vmid: "{{ item.value.id }}"
|
||||
node: "{{ item.value.node }}"
|
||||
state: started
|
||||
loop: "{{ vms_dict | dict2items }}"
|
||||
|
||||
- name: 3. Attendre le boot et l'attribution de l'IP DHCP (Agent QEMU)
|
||||
community.proxmox.proxmox_vm_info:
|
||||
api_host: "{{ proxmox_api_host }}"
|
||||
api_user: "{{ proxmox_user }}"
|
||||
api_token_id: "{{ proxmox_token_id }}"
|
||||
api_token_secret: "{{ proxmox_token_secret }}"
|
||||
validate_certs: false
|
||||
vmid: "{{ item.value.id }}"
|
||||
register: vm_details
|
||||
until:
|
||||
- vm_details.proxmox_vms[0].network_interfaces is defined
|
||||
- (vm_details.proxmox_vms[0].network_interfaces | selectattr('name', 'ne', 'lo') | map(attribute='ip_addresses') | flatten | select('match', '^192\\.') | list | length) > 0
|
||||
retries: 30
|
||||
delay: 5
|
||||
loop: "{{ vms_dict | dict2items }}"
|
||||
|
||||
- name: 4. Construire la liste finale avec les adresses IP
|
||||
set_fact:
|
||||
final_vm_list: >-
|
||||
{%- set result = [] -%}
|
||||
{%- for res in vm_details.results -%}
|
||||
{%- set vm_id = res.item.value.id -%}
|
||||
{%- set vm_name = res.item.value.name -%}
|
||||
{%- set ifaces = res.proxmox_vms[0].network_interfaces | default([]) -%}
|
||||
{%- set ips = [] -%}
|
||||
{%- for iface in ifaces if iface.name != 'lo' -%}
|
||||
{%- for ip in iface.ip_addresses if ip.startswith('192.') or ip.startswith('10.') -%}
|
||||
{%- set _ = ips.append(ip) -%}
|
||||
{%- endfor -%}
|
||||
{%- endfor -%}
|
||||
{%- set main_ip = ips[0] | default('Non attribuée') -%}
|
||||
{%- set _ = result.append({'name': vm_name, 'id': vm_id, 'ip': main_ip}) -%}
|
||||
{%- endfor -%}
|
||||
{{ result }}
|
||||
|
||||
- name: 5. Afficher les résultats à l'écran
|
||||
debug:
|
||||
msg: "VM {{ item.name }} (ID: {{ item.id }}) -> IP DHCP: {{ item.ip }}"
|
||||
loop: "{{ final_vm_list }}"
|
||||
|
||||
- name: 6. Écrire dans le fichier CSV
|
||||
copy:
|
||||
content: |
|
||||
Nom_VM,ID_Proxmox,Adresse_IP
|
||||
{% for vm in final_vm_list %}
|
||||
{{ vm.name }},{{ vm.id }},{{ vm.ip }}
|
||||
{% endfor %}
|
||||
dest: "{{ csv_file_path }}"
|
||||
@@ -0,0 +1,29 @@
|
||||
---
|
||||
- name: Démarrer les VMs créées par OpenTofu
|
||||
hosts: localhost
|
||||
connection: local
|
||||
gather_facts: false
|
||||
vars_files:
|
||||
- proxmox-secret.yml # secret hors git (voir proxmox-secret.yml.sample)
|
||||
|
||||
vars:
|
||||
proxmox_api_host: "192.168.111.220" # Votre nouvelle IP Proxmox
|
||||
proxmox_user: "root@pam"
|
||||
proxmox_token_id: "Stid"
|
||||
|
||||
tasks:
|
||||
- name: Récupérer les IDs des VMs via OpenTofu
|
||||
command: tofu output -json vms_info
|
||||
register: tofu_output_raw
|
||||
|
||||
- name: Démarrer chaque VM sur Proxmox
|
||||
community.general.proxmox_kvm:
|
||||
api_host: "{{ proxmox_api_host }}"
|
||||
api_user: "{{ proxmox_user }}"
|
||||
api_token_id: "{{ proxmox_token_id }}"
|
||||
api_token_secret: "{{ proxmox_token_secret }}"
|
||||
validate_certs: false
|
||||
vmid: "{{ item.value.id }}"
|
||||
node: "{{ item.value.node }}"
|
||||
state: started
|
||||
loop: "{{ (tofu_output_raw.stdout | from_json) | dict2items }}"
|
||||
@@ -0,0 +1,38 @@
|
||||
- name: Orchestration Démarrage et IPs des VMs
|
||||
hosts: localhost
|
||||
connection: local
|
||||
gather_facts: false
|
||||
vars_files:
|
||||
- proxmox-secret.yml # secret hors git (voir proxmox-secret.yml.sample)
|
||||
|
||||
vars:
|
||||
ansible_python_interpreter: "/data/bin/python3"
|
||||
proxmox_api_host: "192.168.111.220" # Votre IP Proxmox
|
||||
proxmox_user: "root@pam"
|
||||
proxmox_token_id: "Stid"
|
||||
csv_file_path: "./machines_ip.csv"
|
||||
|
||||
tasks:
|
||||
- name: "1. Récupérer les données OpenTofu"
|
||||
command: tofu output -json vms_info
|
||||
register: tofu_output_raw
|
||||
changed_when: false
|
||||
|
||||
- name: "2. Extraire la liste des VMs"
|
||||
set_fact:
|
||||
vms_dict: "{{ tofu_output_raw.stdout | from_json }}"
|
||||
|
||||
- name: "3. Arreter les postes de travail sur Proxmox"
|
||||
community.proxmox.proxmox_kvm:
|
||||
api_host: "{{ proxmox_api_host }}"
|
||||
api_user: "{{ proxmox_user }}"
|
||||
api_token_id: "{{ proxmox_token_id }}"
|
||||
api_token_secret: "{{ proxmox_token_secret }}"
|
||||
validate_certs: false
|
||||
vmid: "{{ item.value.id }}"
|
||||
node: "{{ item.value.node }}"
|
||||
state: stopped
|
||||
loop: "{{ vms_dict | dict2items }}"
|
||||
# async: 300
|
||||
# poll: 0
|
||||
|
||||
Reference in new issue
Block a user