Compare commits
74
Commits
lab
..
2d1c4c9934
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2d1c4c9934 | ||
|
|
29ba93e096 | ||
|
|
09862a53c1 | ||
|
|
336f1fd466 | ||
|
|
2937ba4344 | ||
|
|
52eed8aade | ||
|
|
6acf547df1 | ||
|
|
d7f3a7ef06 | ||
|
|
eccd940727 | ||
|
|
52eaeaae93 | ||
|
|
c99279cb49 | ||
|
|
2d9c6ffb1d | ||
|
|
240791d22e | ||
|
|
86e0b4a23f | ||
|
|
1f5d99b5ae | ||
|
|
cd0bfd956c | ||
|
|
6cf28240df | ||
|
|
697ac311a7 | ||
|
|
d08f207fc4 | ||
|
|
74fa6432db | ||
|
|
8ab282eb95 | ||
|
|
3d18c01d5a | ||
|
|
2404692a30 | ||
|
|
557f80979b | ||
|
|
fac4a27b75 | ||
|
|
2d80a76353 | ||
|
|
d5c36e3118 | ||
|
|
ff19c2faae | ||
|
|
4a7e8ef7ca | ||
|
|
3f2b208651 | ||
|
|
fa334f90d4 | ||
|
|
43e535143b | ||
|
|
f0ded8ac17 | ||
|
|
f78c8a6cd7 | ||
|
|
cbcbc45d00 | ||
|
|
869faf720a | ||
|
|
5d39cf3172 | ||
|
|
137b13d94e | ||
|
|
b1008ec425 | ||
|
|
22de950cf5 | ||
|
|
fd0a9a83e8 | ||
|
|
79302e8139 | ||
|
|
1ca4807d4b | ||
|
|
4c086cfad5 | ||
|
|
b91ea08874 | ||
|
|
ac69a7a5c6 | ||
|
|
0a576b7ec0 | ||
|
|
e46f78b971 | ||
|
|
a8b0fca263 | ||
|
|
bbb2e0f024 | ||
|
|
fbf38991d7 | ||
|
|
f672517cc8 | ||
|
|
03a1b243bc | ||
|
|
de745d74dc | ||
|
|
9c49b131e2 | ||
|
|
0912c0a253 | ||
|
|
e2a1e53082 | ||
|
|
80d9befa6a | ||
|
|
fcf5753f57 | ||
|
|
413694f47d | ||
|
|
2e912c7ad5 | ||
|
|
755e736ba9 | ||
|
|
12f3c65c39 | ||
|
|
02b908c4cd | ||
|
|
d059b86dfc | ||
|
|
6e3814ce3f | ||
|
|
fe24fec3a3 | ||
|
|
7d51740a1a | ||
|
|
ca01e8f17e | ||
|
|
b7cf1499a7 | ||
|
|
63db96d1bd | ||
|
|
e1b7a88d1f | ||
|
|
aaf111919d | ||
|
|
f35bd094c7 |
@@ -1,120 +0,0 @@
|
||||
---
|
||||
- name: Create or update a cloud-init Ubuntu template
|
||||
hosts: nodes
|
||||
become: true
|
||||
vars:
|
||||
template_vmid: 900
|
||||
template_os: ubuntu
|
||||
os_release: noble
|
||||
|
||||
template_name: "{{template_os}}-{{ os_release }}-cloud"
|
||||
|
||||
image_filename: "{{ os_release }}-server-cloudimg-amd64.img"
|
||||
image_url: "https://cloud-images.ubuntu.com/{{ os_release }}/current/{{ image_filename }}"
|
||||
image_dest: "/var/lib/vz/template/iso/{{ image_filename }}"
|
||||
|
||||
iso_storage: local
|
||||
vm_storage: ceph-workload
|
||||
|
||||
template_memory: 2048
|
||||
template_cores: 1
|
||||
|
||||
tasks:
|
||||
- name: Check whether the template VMID already exists
|
||||
ansible.builtin.command: qm status {{ template_vmid }}
|
||||
register: template_status
|
||||
changed_when: false
|
||||
failed_when: false
|
||||
|
||||
- name: Check if the cloud image file exists
|
||||
ansible.builtin.stat:
|
||||
path: "{{ image_dest }}"
|
||||
register: image_exists
|
||||
changed_when: false
|
||||
failed_when: false
|
||||
|
||||
- name: Set candidate information
|
||||
ansible.builtin.set_fact:
|
||||
has_image_file: "{{ image_exists.stat.exists }}"
|
||||
root_free_space: "{{ (ansible_facts['mounts'] | selectattr('mount', 'equalto', '/') | first).size_available }}"
|
||||
|
||||
- name: Select target host
|
||||
ansible.builtin.set_fact:
|
||||
target_host: >-
|
||||
{{ (ansible_play_hosts
|
||||
| map('extract', hostvars)
|
||||
| selectattr('has_image_file', 'equalto', true)
|
||||
| sort(attribute='root_free_space', reverse=true)
|
||||
| map(attribute='inventory_hostname')
|
||||
| first)
|
||||
| default(ansible_play_hosts
|
||||
| map('extract', hostvars)
|
||||
| sort(attribute='root_free_space', reverse=true)
|
||||
| map(attribute='inventory_hostname')
|
||||
| first,
|
||||
true) }}
|
||||
run_once: true
|
||||
|
||||
- name: Download the current Ubuntu cloud image
|
||||
ansible.builtin.get_url:
|
||||
url: "{{ image_url }}"
|
||||
dest: "{{ image_dest }}"
|
||||
force: false
|
||||
mode: "0644"
|
||||
register: image_download
|
||||
when: inventory_hostname == target_host
|
||||
|
||||
- name: Destroy existing template if present
|
||||
ansible.builtin.command: qm destroy {{ template_vmid }} --purge
|
||||
when:
|
||||
- template_status.rc == 0
|
||||
- image_download.changed
|
||||
|
||||
- name: Rebuild the template
|
||||
when:
|
||||
- inventory_hostname == target_host
|
||||
- image_download.changed or
|
||||
template_status.rc != 0
|
||||
block:
|
||||
|
||||
- name: Create the base VM shell
|
||||
ansible.builtin.command: >
|
||||
qm create {{ template_vmid }}
|
||||
--memory {{ template_memory }}
|
||||
--core {{ template_cores }}
|
||||
--net0 virtio,bridge=vmbr0
|
||||
--scsihw virtio-scsi-pci
|
||||
--bios ovmf
|
||||
--machine q35
|
||||
--efidisk0 {{ vm_storage }}:0,pre-enrolled-keys=0
|
||||
--name {{ template_name }}
|
||||
|
||||
- name: Import the cloud image as the primary disk
|
||||
ansible.builtin.command: qm set {{ template_vmid }} --scsi0 {{ vm_storage }}:0,import-from={{ image_dest }}
|
||||
|
||||
- name: Attach a cloud-init drive
|
||||
ansible.builtin.command: qm set {{ template_vmid }} --scsi1 {{ vm_storage }}:cloudinit
|
||||
|
||||
- name: Set boot order to the primary disk
|
||||
ansible.builtin.command: qm set {{ template_vmid }} --boot order=scsi0
|
||||
|
||||
- name: Add serial console for cloud-init consoles
|
||||
ansible.builtin.command: qm set {{ template_vmid }} --serial0 socket --vga serial0
|
||||
|
||||
- name: Convert the VM to a template
|
||||
ansible.builtin.command: qm template {{ template_vmid }}
|
||||
|
||||
- name: Send notification
|
||||
ansible.builtin.uri:
|
||||
url: "{{ ntfy_url }}/{{ ntfy_topic }}"
|
||||
method: POST
|
||||
user: "{{ ntfy_user }}"
|
||||
password: "{{ lookup('env', 'NTFY_PASSWORD') }}"
|
||||
force_basic_auth: true
|
||||
body: |
|
||||
The {{ template_os | capitalize }} {{ os_release }} cloud-init template has been successfully updated on {{ inventory_hostname }}.
|
||||
headers:
|
||||
Title: "Cloud-init template updated"
|
||||
Priority: "min"
|
||||
Tags: "white_check_mark"
|
||||
when: ntfy_url is defined
|
||||
@@ -12,7 +12,7 @@ variable "node_datastore" {
|
||||
variable "vm_template" {
|
||||
description = "Template of the VM"
|
||||
type = string
|
||||
default = "ubuntu-noble-cloud"
|
||||
default = "ubuntu-cloud"
|
||||
}
|
||||
|
||||
variable "vm_name" {
|
||||
|
||||
@@ -6,7 +6,7 @@ resource "proxmox_vm_qemu" "cloudinit-test" {
|
||||
|
||||
target_node = "zenith"
|
||||
|
||||
clone = "ubuntu-noble-cloud"
|
||||
clone = "ubuntu-cloud"
|
||||
|
||||
agent = 0
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ variable "node_datastore" {
|
||||
variable "vm_template" {
|
||||
description = "Template of the VM"
|
||||
type = string
|
||||
default = "ubuntu-noble-cloud"
|
||||
default = "ubuntu-cloud"
|
||||
}
|
||||
|
||||
variable "vm_name" {
|
||||
|
||||
Reference in New Issue
Block a user