Fix setup for CoreOS

This commit is contained in:
2026-06-15 00:16:45 +02:00
parent 9c0fcde94e
commit 211ebc15e9
7 changed files with 73 additions and 37 deletions
+24
View File
@@ -0,0 +1,24 @@
#!/bin/bash
# VM names from vars/vms.yml
VMS=("coreos-vm" "flatcar-vm" "microos-vm")
# Image directory from group_vars/all.yml
IMAGES_DIR="/var/lib/libvirt/images"
for vm in "${VMS[@]}"; do
echo "Cleaning up VM: $vm"
# Destroy the VM (force stop)
sudo virsh destroy "$vm" 2>/dev/null || echo "VM $vm is not running."
# Undefine the VM (remove configuration)
sudo virsh undefine "$vm" 2>/dev/null || echo "VM $vm is not defined."
# Remove the disk image
sudo rm -f "$IMAGES_DIR/$vm.qcow2"
sudo rm -f "$IMAGES_DIR/$vm.download"
echo "VM $vm cleaned up."
done
echo "Cleanup complete."
+1 -1
View File
@@ -7,7 +7,7 @@ vm_ssh_public_key: "~/.ssh/id_vms.pub" # Path to your public key for SSH access
# Default VM resources
default_cpu: 2
default_ram: 2048
default_disk: "20G"
default_disk: 20 # GB
# Storage path for images
vm_images_dir: "/var/lib/libvirt/images"
+12 -6
View File
@@ -1,12 +1,18 @@
---
- name: Generate Ignition config for CoreOS/Flatcar
- name: Generate Ignition configuration for CoreOS/Flatcar
template:
src: ignition.json.j2
dest: "/tmp/{{ vm_name }}_ignition.json"
when: os_type == "coreos" or os_type == "flatcar"
dest: "{{ vm_images_dir }}/{{ vm_name }}.ign"
when: os_type == 'coreos' or os_type == 'flatcar'
- name: Generate Cloud-init config for MicroOS
- name: Generate Cloud-init configuration for MicroOS
template:
src: user-data.yaml.j2
dest: "/tmp/{{ vm_name }}_user-data"
when: os_type == "microos"
dest: "{{ vm_images_dir }}/{{ vm_name }}_user-data"
when: os_type == 'microos'
- name: Generate dummy meta-data file
copy:
content: "instance-id: {{ vm_name }}\nlocal-hostname: {{ vm_name }}\n"
dest: "{{ vm_images_dir }}/{{ vm_name }}_meta-data"
@@ -1,26 +1,16 @@
{
"ignition": {
"version": "0.3.0"
"version": "3.4.0"
},
"passwd": {
"users": [
{
"name": "{{ vm_user }}",
"password_hash": "{{ vm_password | password_hash('sha512') }}",
"ssh_public_keys": [
"{{ lookup('file', vm_ssh_public_key) }}"
"passwordHash": "{{ vm_password | password_hash('sha512') }}",
"sshAuthorizedKeys": [
"{{ lookup('file', vm_ssh_public_key) | trim }}"
]
}
]
},
"storage": {
"files": [
{
"path": "/etc/ssh/sshd_config.d/permit_root_login.conf",
"contents": {
"source": "data:text/plain;charset=utf-8,PermitRootLogin yes"
}
}
]
}
}
}
@@ -3,6 +3,17 @@ users:
- name: {{ vm_user }}
passwd: {{ vm_password | password_hash('sha512') }}
ssh_authorized_keys:
- {{ lookup('file', vm_ssh_public_key) }}
- {{ lookup('file', vm_ssh_public_key) | trim }}
sudo: ALL=(ALL) NOPASSWD:ALL
lock_passwd: false
- name: root
passwd: {{ vm_password | password_hash('sha512') }}
sudo: ALL=(ALL) NOPASSWD:ALL
lock_passwd: false
runcmd:
- mkdir -p /etc/ssh/sshd_config.d
- echo "PermitRootLogin yes" > /etc/ssh/sshd_config.d/permit_root_login.conf
- systemctl restart sshd
@@ -1,5 +1,4 @@
---
- name: Define image URLs
set_fact:
os_images:
@@ -43,6 +42,21 @@
- name: Provision VM using virt-install
shell: |
{% if os_type == 'coreos' or os_type == 'flatcar' %}
virt-install \
--connect qemu:///system \
--name {{ vm_name }} \
--vcpus {{ cpu | default(default_cpu) }} \
--memory {{ ram | default(default_ram) }} \
--disk size={{ disk | default('10G') }},backing_store={{ vm_images_dir }}/{{ vm_name }}.qcow2,backing_format=qcow2 \
--boot hd \
--os-variant {{ os_variant }} \
--network network=default \
--graphics none \
--noautoconsole \
--boot uefi \
--sysinfo type=fwcfg,entry0.name=opt/com.coreos/config,entry0.file={{ vm_images_dir }}/{{ vm_name }}.ign
{% elif os_type == 'microos' %}
virt-install \
--name {{ vm_name }} \
--vcpus {{ cpu | default(default_cpu) }} \
@@ -54,16 +68,7 @@
--graphics none \
--noautoconsole \
--boot uefi \
{% if os_type == 'coreos' or os_type == 'flatcar' %}
--cloud-init user-data=/tmp/{{ vm_name }}_ignition.json
{% elif os_type == 'microos' %}
--cloud-init user-data=/tmp/{{ vm_name }}_user-data
--cloud-init user-data={{ vm_images_dir }}/{{ vm_name }}_user-data,meta-data={{ vm_images_dir }}/{{ vm_name }}_meta-data
{% endif %}
args:
creates: "/etc/libvirt/qemu/{{ vm_name }}.xml"
- name: Attach configuration to VM
debug:
msg: "Configuration is now handled by virt-install --cloud-init flag."
when: false # This task is now obsolete
become: yes
creates: "/etc/libvirt/qemu/{{ vm_name }}.xml"
+2 -2
View File
@@ -5,14 +5,14 @@ vms:
os_variant: "fedora-coreos-stable"
cpu: 2
ram: 2048
disk: "20G"
disk: 20 # GB
- name: flatcar-vm
os_type: flatcar
os_variant: "fedora-coreos-stable"
cpu: 2
ram: 2048
disk: "20G"
disk: 20 # GB
- name: microos-vm
os_type: microos