Create VM from clone delivered.
This commit is contained in:
@@ -9,6 +9,6 @@
|
|||||||
ansible.builtin.lineinfile:
|
ansible.builtin.lineinfile:
|
||||||
path: /etc/sudoers
|
path: /etc/sudoers
|
||||||
state: present
|
state: present
|
||||||
regexp: '^%wheel'
|
regexp: "^%wheel"
|
||||||
line: '%wheel ALL=(ALL) NOPASSWD:ALL'
|
line: "%wheel ALL=(ALL) NOPASSWD:ALL"
|
||||||
validate: 'visudo -cf %s'
|
validate: "visudo -cf %s"
|
||||||
|
|||||||
@@ -3,6 +3,10 @@ proxmox:
|
|||||||
hosts:
|
hosts:
|
||||||
pve0[1:3]:
|
pve0[1:3]:
|
||||||
|
|
||||||
|
dhcp_server:
|
||||||
|
hosts:
|
||||||
|
matchbox:
|
||||||
|
|
||||||
unbound_servers:
|
unbound_servers:
|
||||||
hosts:
|
hosts:
|
||||||
unbound02:
|
unbound02:
|
||||||
@@ -19,9 +23,9 @@ ipaserver:
|
|||||||
hosts:
|
hosts:
|
||||||
infra01.int.mk-labs.cloud:
|
infra01.int.mk-labs.cloud:
|
||||||
|
|
||||||
matchbox:
|
# matchbox:
|
||||||
hosts:
|
# hosts:
|
||||||
infra01:
|
# infra01:
|
||||||
|
|
||||||
hub_cluster:
|
hub_cluster:
|
||||||
hosts:
|
hosts:
|
||||||
|
|||||||
39
infra-config/playbooks/add_dhcp_entry.yml
Normal file
39
infra-config/playbooks/add_dhcp_entry.yml
Normal 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
|
||||||
@@ -3,12 +3,17 @@
|
|||||||
hosts: all
|
hosts: all
|
||||||
gather_facts: false
|
gather_facts: false
|
||||||
|
|
||||||
|
- name: Proxmox Clone VM Playbook
|
||||||
|
ansible.builtin.import_playbook: proxmox_clone_vm.yml
|
||||||
|
|
||||||
- name: DNS Playbook
|
- name: DNS Playbook
|
||||||
ansible.builtin.import_playbook: add_dns_entry.yml
|
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
|
- name: Start VM Playbook
|
||||||
ansible.builtin.import_playbook: proxmox_clone_vm.yml
|
ansible.builtin.import_playbook: proxmox_start_vm.yml
|
||||||
# - name: Set Hostname Playbook
|
|
||||||
# ansible.builtin.import_playbook: set_hostname.yml
|
- name: Set Hostname Playbook
|
||||||
|
ansible.builtin.import_playbook: set_hostname.yml
|
||||||
|
|||||||
@@ -24,32 +24,6 @@
|
|||||||
storage: "{{ vm_storage }}"
|
storage: "{{ vm_storage }}"
|
||||||
format: raw
|
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
|
# - name: Add VM to HA group
|
||||||
# community.proxmox.proxmox_cluster_ha_resources:
|
# community.proxmox.proxmox_cluster_ha_resources:
|
||||||
# api_user: "{{ proxmox_user }}"
|
# api_user: "{{ proxmox_user }}"
|
||||||
@@ -60,4 +34,3 @@
|
|||||||
# group: "{{ ha_group }}"
|
# group: "{{ ha_group }}"
|
||||||
# max_relocate: 2
|
# max_relocate: 2
|
||||||
# max_restart: 2
|
# max_restart: 2
|
||||||
#
|
|
||||||
32
infra-config/playbooks/proxmox_start_vm.yml
Normal file
32
infra-config/playbooks/proxmox_start_vm.yml
Normal 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
|
||||||
@@ -1,10 +1,12 @@
|
|||||||
---
|
---
|
||||||
- name: Create VM ID from IP address for Proxmox hosts
|
- name: Set hostname of VM
|
||||||
hosts: all
|
hosts: all
|
||||||
gather_facts: false
|
gather_facts: false
|
||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
- name: Set hostname of VM
|
- name: Set hostname of VM
|
||||||
|
become: true
|
||||||
delegate_to: "{{ inventory_hostname }}"
|
delegate_to: "{{ inventory_hostname }}"
|
||||||
ansible.builtin.hostname:
|
ansible.builtin.hostname:
|
||||||
name: "{{ hostname }}"
|
name: "{{ hostname }}"
|
||||||
|
#delay: 20
|
||||||
|
|||||||
Reference in New Issue
Block a user