Create VM from clone delivered.

This commit is contained in:
2025-07-10 11:53:47 -05:00
parent 8212a69802
commit 98cad7348c
7 changed files with 104 additions and 49 deletions

View File

@@ -0,0 +1,39 @@
---
- name: Add entry to DNSMasq
hosts: all
gather_facts: false
tasks:
- name: Retrieve information about specific VM by name and get current configuration
delegate_to: "localhost"
community.proxmox.proxmox_vm_info:
api_user: "{{ proxmox_user }}"
api_password: "{{ proxmox_password }}"
api_host: "{{ proxmox_host }}"
name: "{{ inventory_hostname }}"
config: current
register: proxmox_vm_info
- name: Extract net0 information
set_fact:
vm_net0: "{{ proxmox_vm_info.proxmox_vms[0].config.net0 }}"
- name: Extract MAC address using regex
set_fact:
vm_mac_address: "{{ vm_net0 | regex_search('([0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2}') }}"
- name: Add line to hosts file
delegate_to: "{{ groups['dhcp_server'][0] }}"
become: true
ansible.builtin.lineinfile:
path: /etc/dnsmasq.d/hosts.conf
regexp: "# {{ inventory_hostname }}$"
line: "dhcp-host={{ vm_mac_address|lower }},{{ ip_address }} # {{ inventory_hostname }}"
state: present
# restart dnsmasq service
- name: Restart service dnsmasq
delegate_to: "{{ groups['dhcp_server'][0] }}"
become: true
ansible.builtin.service:
name: dnsmasq
state: restarted