refactor(ansible): Estandariza nombres de roles y actualiza Koji

Se estandarizan los nombres de los directorios de roles, cambiando guiones por guiones bajos.

Se añaden nuevos scripts para limpieza y callbacks en Koji Hub. Además, se actualizan las configuraciones de Kojid, Kojira y PostgreSQL, incluyendo la instalación de paquetes, ajustes de mock y la gestión de variables.
This commit is contained in:
Rénich Bon Ćirić 2025-11-15 20:07:11 -06:00
commit 39aeb2d6b6
Signed by: renich
GPG key ID: AB2A9F49384FE324
91 changed files with 1037 additions and 957 deletions

View file

@ -8,4 +8,12 @@ apply:
.PHONY: destroy
destroy:
virsh -c qemu:///system destroy cs10-koji-00.mx-os
virsh -c qemu:///system destroy cs10-koji-01.mx-os
virsh -c qemu:///system destroy cs10-koji-02.mx-os
virsh -c qemu:///system destroy cs10-koji-03.mx-os
virsh -c qemu:///system undefine --remove-all-storage --nvram --tpm cs10-koji-00.mx-os
virsh -c qemu:///system undefine --remove-all-storage --nvram --tpm cs10-koji-01.mx-os
virsh -c qemu:///system undefine --remove-all-storage --nvram --tpm cs10-koji-02.mx-os
virsh -c qemu:///system undefine --remove-all-storage --nvram --tpm cs10-koji-03.mx-os
tofu destroy -auto-approve

View file

@ -1,30 +1,3 @@
resource "libvirt_volume" "cs10-base" {
count = var.guest_count
name = "${var.guest_base_name}-${format("%02d", count.index)}.${var.domain}-system.qcow2"
pool = var.pool_name
format = "qcow2"
create = {
content = {
url = "file://${var.base_image_path}"
}
}
}
resource "libvirt_cloudinit_disk" "cs10-cloudinit" {
count = var.guest_count
name = "${var.guest_base_name}-${format("%02d", count.index)}-cloudinit.iso"
user_data = templatefile("templates/cloudinit.cfg.tftpl", {
root_password = var.root_password
hostname = "${var.guest_base_name}-${format("%02d", count.index)}.${var.domain}"
})
meta_data = yamlencode({
instance-id = "${var.guest_base_name}-${format("%02d", count.index)}.${var.domain}"
local-hostname = "${var.guest_base_name}-${format("%02d", count.index)}.${var.domain}"
})
}
resource "libvirt_domain" "cs10-base" {
count = var.guest_count
name = "${var.guest_base_name}-${format("%02d", count.index)}.${var.domain}"
@ -35,22 +8,22 @@ resource "libvirt_domain" "cs10-base" {
autostart = true
type = "kvm"
os = {
type = "hvm"
arch = "x86_64"
machine = "q35"
firmware = "efi"
loader_path = "/usr/share/edk2/ovmf/OVMF_CODE_4M.secboot.qcow2"
loader_readonly = true
loader_secure = true
loader_type = "pflash"
nvram = {
path = "/var/lib/libvirt/qemu/nvram/${var.guest_base_name}-${format("%02d", count.index)}.${var.domain}_VARS.qcow2"
template = "/usr/share/edk2/ovmf/OVMF_VARS_4M.secboot.qcow2"
format = "qcow2"
}
boot_devices = ["hd"]
}
os = {
type = "hvm"
arch = "x86_64"
machine = "q35"
firmware = "efi"
loader_path = "/usr/share/edk2/ovmf/OVMF_CODE_4M.secboot.qcow2"
loader_readonly = true
loader_secure = true
loader_type = "pflash"
nvram = {
path = "/var/lib/libvirt/qemu/nvram/${var.guest_base_name}-${format("%02d", count.index)}.${var.domain}_VARS.qcow2"
template = "/usr/share/edk2/ovmf/OVMF_VARS_4M.secboot.qcow2"
format = "qcow2"
}
boot_devices = ["hd"]
}
cpu = {
mode = "host-passthrough"
@ -64,19 +37,34 @@ resource "libvirt_domain" "cs10-base" {
devices = {
disks = [
{
type = "volume"
driver = "qcow2"
source = {
file = libvirt_volume.cs10-base[count.index].path
pool = var.pool_name
volume = libvirt_volume.cs10-base[count.index].name
}
target = {
dev = "vda"
bus = "virtio"
}
target = { dev = "vda" }
bus = "virtio"
},
{
source = {
file = libvirt_cloudinit_disk.cs10-cloudinit[count.index].path
}
target = { dev = "sda" }
bus = "sata"
type = "volume"
device = "cdrom"
readonly = true
driver = "raw"
source = {
pool = var.pool_name
volume = libvirt_cloudinit_disk.cs10-cloudinit[count.index].name
}
target = {
dev = "sda"
bus = "sata"
}
}
]
@ -105,7 +93,7 @@ resource "libvirt_domain" "cs10-base" {
rngs = [
{
model = "virtio"
model = "virtio"
device = "/dev/urandom"
}
]
@ -120,7 +108,7 @@ resource "libvirt_domain" "cs10-base" {
tpms = [
{
model = "tpm-crb"
model = "tpm-crb"
backend_type = "emulator"
backend_version = "2.0"
}
@ -137,4 +125,73 @@ resource "libvirt_domain" "cs10-base" {
type = "virtio"
}
}
# configuración por scripts
provisioner "file" {
source = "scripts"
destination = "/tmp"
connection {
type = "ssh"
host = self.name
timeout = "1m"
}
}
provisioner "remote-exec" {
inline = [
"bash /tmp/scripts/set-hostname.bash ${self.name}",
"bash /tmp/scripts/dnf-config.bash",
"bash /tmp/scripts/install-tools.bash",
"bash /tmp/scripts/upgrade.bash"
]
connection {
type = "ssh"
user = "root"
host = self.name
timeout = "1m"
}
}
}
resource "libvirt_volume" "cs10-base" {
count = var.guest_count
name = "${var.guest_base_name}-${format("%02d", count.index)}.${var.domain}-system.qcow2"
pool = var.pool_name
format = "qcow2"
create = {
content = {
url = "file://${var.base_image_path}"
}
}
}
resource "libvirt_cloudinit_disk" "cs10-cloudinit" {
count = var.guest_count
name = "${var.guest_base_name}-${format("%02d", count.index)}.${var.domain}-cloudinit.iso"
user_data = templatefile("templates/cloudinit.cfg.tftpl", {
root_password = var.root_password
hostname = "${var.guest_base_name}-${format("%02d", count.index)}.${var.domain}"
})
meta_data = yamlencode({
instance-id = "${var.guest_base_name}-${format("%02d", count.index)}.${var.domain}"
local-hostname = "${var.guest_base_name}-${format("%02d", count.index)}.${var.domain}"
})
}
resource "libvirt_volume" "cloudinit" {
count = var.guest_count
name = "${var.guest_base_name}-${format("%02d", count.index)}.${var.domain}-cloudinit.iso"
pool = var.pool_name
format = "iso"
create = {
content = {
url = libvirt_cloudinit_disk.cs10-cloudinit[count.index].path
}
}
}

View file

@ -1,190 +0,0 @@
<domain type='kvm'>
<name>cs10</name>
<uuid>dd0ce3f5-a2c0-4bc9-8b1f-e92edeaf196d</uuid>
<metadata>
<libosinfo:libosinfo xmlns:libosinfo="http://libosinfo.org/xmlns/libvirt/domain/1.0">
<libosinfo:os id="http://centos.org/centos-stream/10"/>
</libosinfo:libosinfo>
</metadata>
<memory unit='KiB'>8388608</memory>
<currentMemory unit='KiB'>8388608</currentMemory>
<vcpu placement='static'>4</vcpu>
<os firmware='efi'>
<type arch='x86_64' machine='pc-q35-10.1'>hvm</type>
<firmware>
<feature enabled='yes' name='enrolled-keys'/>
<feature enabled='yes' name='secure-boot'/>
</firmware>
<loader readonly='yes' secure='yes' type='pflash' format='qcow2'>/usr/share/edk2/ovmf/OVMF_CODE_4M.secboot.qcow2</loader>
<nvram template='/usr/share/edk2/ovmf/OVMF_VARS_4M.secboot.qcow2' templateFormat='qcow2' format='qcow2'>/var/lib/libvirt/qemu/nvram/cs10_VARS.qcow2</nvram>
<boot dev='hd'/>
</os>
<features>
<acpi/>
<apic/>
<vmport state='off'/>
<smm state='on'/>
</features>
<cpu mode='host-passthrough' check='none' migratable='on'/>
<clock offset='utc'>
<timer name='rtc' tickpolicy='catchup'/>
<timer name='pit' tickpolicy='delay'/>
<timer name='hpet' present='no'/>
</clock>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<pm>
<suspend-to-mem enabled='no'/>
<suspend-to-disk enabled='no'/>
</pm>
<devices>
<emulator>/usr/bin/qemu-system-x86_64</emulator>
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2'/>
<source file='/home/renich/VirtualMachines/cs10.qcow2'/>
<target dev='vda' bus='virtio'/>
<address type='pci' domain='0x0000' bus='0x04' slot='0x00' function='0x0'/>
</disk>
<controller type='usb' index='0' model='qemu-xhci' ports='15'>
<address type='pci' domain='0x0000' bus='0x02' slot='0x00' function='0x0'/>
</controller>
<controller type='pci' index='0' model='pcie-root'/>
<controller type='pci' index='1' model='pcie-root-port'>
<model name='pcie-root-port'/>
<target chassis='1' port='0x10'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0' multifunction='on'/>
</controller>
<controller type='pci' index='2' model='pcie-root-port'>
<model name='pcie-root-port'/>
<target chassis='2' port='0x11'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x1'/>
</controller>
<controller type='pci' index='3' model='pcie-root-port'>
<model name='pcie-root-port'/>
<target chassis='3' port='0x12'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x2'/>
</controller>
<controller type='pci' index='4' model='pcie-root-port'>
<model name='pcie-root-port'/>
<target chassis='4' port='0x13'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x3'/>
</controller>
<controller type='pci' index='5' model='pcie-root-port'>
<model name='pcie-root-port'/>
<target chassis='5' port='0x14'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x4'/>
</controller>
<controller type='pci' index='6' model='pcie-root-port'>
<model name='pcie-root-port'/>
<target chassis='6' port='0x15'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x5'/>
</controller>
<controller type='pci' index='7' model='pcie-root-port'>
<model name='pcie-root-port'/>
<target chassis='7' port='0x16'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x6'/>
</controller>
<controller type='pci' index='8' model='pcie-root-port'>
<model name='pcie-root-port'/>
<target chassis='8' port='0x17'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x7'/>
</controller>
<controller type='pci' index='9' model='pcie-root-port'>
<model name='pcie-root-port'/>
<target chassis='9' port='0x18'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0' multifunction='on'/>
</controller>
<controller type='pci' index='10' model='pcie-root-port'>
<model name='pcie-root-port'/>
<target chassis='10' port='0x19'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x1'/>
</controller>
<controller type='pci' index='11' model='pcie-root-port'>
<model name='pcie-root-port'/>
<target chassis='11' port='0x1a'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x2'/>
</controller>
<controller type='pci' index='12' model='pcie-root-port'>
<model name='pcie-root-port'/>
<target chassis='12' port='0x1b'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x3'/>
</controller>
<controller type='pci' index='13' model='pcie-root-port'>
<model name='pcie-root-port'/>
<target chassis='13' port='0x1c'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x4'/>
</controller>
<controller type='pci' index='14' model='pcie-root-port'>
<model name='pcie-root-port'/>
<target chassis='14' port='0x1d'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x5'/>
</controller>
<controller type='sata' index='0'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x1f' function='0x2'/>
</controller>
<controller type='virtio-serial' index='0'>
<address type='pci' domain='0x0000' bus='0x03' slot='0x00' function='0x0'/>
</controller>
<controller type='scsi' index='0' model='virtio-scsi'>
<address type='pci' domain='0x0000' bus='0x07' slot='0x00' function='0x0'/>
</controller>
<interface type='network'>
<mac address='52:54:00:62:40:d9'/>
<source network='default'/>
<model type='virtio'/>
<address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
</interface>
<serial type='pty'>
<target type='isa-serial' port='0'>
<model name='isa-serial'/>
</target>
</serial>
<console type='pty'>
<target type='serial' port='0'/>
</console>
<channel type='unix'>
<target type='virtio' name='org.qemu.guest_agent.0'/>
<address type='virtio-serial' controller='0' bus='0' port='1'/>
</channel>
<channel type='spicevmc'>
<target type='virtio' name='com.redhat.spice.0'/>
<address type='virtio-serial' controller='0' bus='0' port='2'/>
</channel>
<input type='tablet' bus='usb'>
<address type='usb' bus='0' port='1'/>
</input>
<input type='mouse' bus='ps2'/>
<input type='keyboard' bus='ps2'/>
<tpm model='tpm-crb'>
<backend type='emulator' version='2.0'/>
</tpm>
<graphics type='spice' autoport='yes'>
<listen type='address'/>
<image compression='off'/>
</graphics>
<sound model='ich9'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x1b' function='0x0'/>
</sound>
<audio id='1' type='spice'/>
<video>
<model type='virtio' heads='1' primary='yes'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x0'/>
</video>
<redirdev bus='usb' type='spicevmc'>
<address type='usb' bus='0' port='2'/>
</redirdev>
<redirdev bus='usb' type='spicevmc'>
<address type='usb' bus='0' port='3'/>
</redirdev>
<watchdog model='itco' action='reset'/>
<memballoon model='virtio'>
<address type='pci' domain='0x0000' bus='0x05' slot='0x00' function='0x0'/>
</memballoon>
<rng model='virtio'>
<backend model='random'>/dev/urandom</backend>
<address type='pci' domain='0x0000' bus='0x06' slot='0x00' function='0x0'/>
</rng>
</devices>
</domain>

View file

@ -9,6 +9,3 @@ terraform {
provider "libvirt" {
uri = "qemu:///system"
}

View file

@ -1,10 +0,0 @@
#!/usr/bin/bash
cat << EOF >> /etc/dnf/dnf.conf
# get me the fastest mirrors!
max_parallel_downloads = 10
minrate=1M
timeout=10
EOF

View file

@ -5,6 +5,13 @@ variable "root_password" {
default = "Un pinche pass."
}
# hostname and domain name
variable "guest_base_name" {
description = "Nombre base para las máquinas virtuales invitadas."
type = string
default = "cs10-koji"
}
variable "domain" {
description = "Dominio de red para las máquinas virtuales."
type = string
@ -12,28 +19,18 @@ variable "domain" {
default = "mx-os"
}
variable "guest_count" {
description = "Número de máquinas virtuales a crear"
type = number
default = 1
}
variable "guest_base_name" {
description = "Nombre base para las máquinas virtuales invitadas."
type = string
default = "cs10-koji"
}
# base image
variable "base_image_path" {
description = "Path to the base qcow2 image"
type = string
default = "/home/renich/VirtualMachines/cs10.qcow2"
}
variable "guest_memory" {
description = "Cantidad de memoria RAM para cada invitado en MB."
# resources
variable "guest_count" {
description = "Número de máquinas virtuales a crear"
type = number
default = 4096
default = 4
}
variable "guest_vcpu" {
@ -42,10 +39,10 @@ variable "guest_vcpu" {
default = 2
}
variable "disk_size" {
description = "Tamaño del disco del sistema para cada invitado en bytes."
variable "guest_memory" {
description = "Cantidad de memoria RAM para cada invitado en MB."
type = number
default = 107374182400 # 100 GB
default = 4096
}
variable "pool_name" {
@ -53,4 +50,3 @@ variable "pool_name" {
type = string
default = "fast"
}