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

@@ -9,6 +9,6 @@
ansible.builtin.lineinfile:
path: /etc/sudoers
state: present
regexp: '^%wheel'
line: '%wheel ALL=(ALL) NOPASSWD:ALL'
validate: 'visudo -cf %s'
regexp: "^%wheel"
line: "%wheel ALL=(ALL) NOPASSWD:ALL"
validate: "visudo -cf %s"

View File

@@ -3,6 +3,10 @@ proxmox:
hosts:
pve0[1:3]:
dhcp_server:
hosts:
matchbox:
unbound_servers:
hosts:
unbound02:
@@ -19,9 +23,9 @@ ipaserver:
hosts:
infra01.int.mk-labs.cloud:
matchbox:
hosts:
infra01:
# matchbox:
# hosts:
# infra01:
hub_cluster:
hosts:

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

View File

@@ -3,12 +3,17 @@
hosts: all
gather_facts: false
- name: Proxmox Clone VM Playbook
ansible.builtin.import_playbook: proxmox_clone_vm.yml
- name: DNS Playbook
ansible.builtin.import_playbook: add_dns_entry.yml
# Create DHCP Reservation
- name: DHCP Playbook
ansible.builtin.import_playbook: add_dhcp_entry.yml
- name: Proxmox Clone VM Playbook
ansible.builtin.import_playbook: proxmox_clone_vm.yml
# - name: Set Hostname Playbook
# ansible.builtin.import_playbook: set_hostname.yml
- name: Start VM Playbook
ansible.builtin.import_playbook: proxmox_start_vm.yml
- name: Set Hostname Playbook
ansible.builtin.import_playbook: set_hostname.yml

View File

@@ -24,32 +24,6 @@
storage: "{{ vm_storage }}"
format: raw
- name: Retrieve information about specific VM by name and get current configuration
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: Start VM
# community.proxmox.proxmox_kvm:
# api_user: "{{ proxmox_user }}"
# api_password: "{{ proxmox_password }}"
# api_host: "{{ proxmox_host }}"
# name: "{{ inventory_hostname }}"
# node: "{{ proxmox_target_node }}"
# state: started
# - name: Add VM to HA group
# community.proxmox.proxmox_cluster_ha_resources:
# api_user: "{{ proxmox_user }}"
@@ -60,4 +34,3 @@
# group: "{{ ha_group }}"
# max_relocate: 2
# max_restart: 2
#

View File

@@ -0,0 +1,32 @@
---
- name: Create VM ID from IP address for Proxmox hosts
hosts: all
gather_facts: false
tasks:
- name: Start Proxmox VM
delegate_to: "localhost"
when: platform is defined and platform == "proxmox"
community.proxmox.proxmox_kvm:
api_user: "{{ proxmox_user }}"
api_password: "{{ proxmox_password }}"
api_host: "{{ proxmox_host }}"
name: "{{ inventory_hostname }}"
node: "{{ proxmox_clone_node }}"
state: started
# - name: Wait for the VM to start
# delegate_to: "localhost"
# wait_for:
# port: 22
# host: "{{ inventory_hostname }}"
# search_regex: OpenSSH
# delay: 10
# timeout: 60
# - name: Wait for the reboot to complete if there was a change.
# wait_for_connection:
# connect_timeout: 10
# sleep: 5
# delay: 5
# timeout: 300

View File

@@ -1,10 +1,12 @@
---
- name: Create VM ID from IP address for Proxmox hosts
- name: Set hostname of VM
hosts: all
gather_facts: false
tasks:
- name: Set hostname of VM
become: true
delegate_to: "{{ inventory_hostname }}"
ansible.builtin.hostname:
name: "{{ hostname }}"
#delay: 20