Change back to cloud init

This commit is contained in:
2026-06-10 18:45:25 +02:00
parent 223b787675
commit fdd7ca8016
4 changed files with 14 additions and 15 deletions
+8
View File
@@ -9,6 +9,14 @@
- kvm_host_setup
tasks:
- name: Provision each VM
include_role:
name: os_config
vars:
vm_name: "{{ item.name }}"
os_type: "{{ item.os_type }}"
loop: "{{ vms }}"
- name: Launch each VM
include_role:
name: vm_provision
@@ -1,5 +1,7 @@
---
---
- name: Generate Cloud-init config
template:
src: "{{ 'user-data-coreos.yaml.j2' if os_type in ['coreos', 'flatcar'] else 'user-data.yaml.j2' }}"
src: user-data.yaml.j2
dest: "/tmp/{{ vm_name }}_user-data"
@@ -1,8 +1,7 @@
#cloud-config
users:
- name: {{ vm_user }}
passwd: {{ vm_password | password_hash('sha512') }}
sudo: ALL=(ALL) NOPASSWD:ALL
ssh_authorized_keys:
- {{ lookup('file', vm_ssh_public_key | replace('~', lookup('env', 'HOME'))) }}
sudo: ALL=(ALL) NOPASSWD:ALL
lock_passwd: false
@@ -41,17 +41,6 @@
args:
creates: "{{ vm_images_dir }}/{{ vm_name }}.qcow2"
- name: Customize VM image (Inject User/SSH/Sudo)
shell: |
virt-customize -a {{ vm_images_dir }}/{{ vm_name }}.qcow2 \
--run-command "useradd -m -G wheel {{ vm_user }}" \
--password {{ vm_user }}:password:{{ vm_password }} \
--ssh-inject {{ vm_user }}:file:{{ vm_ssh_public_key | replace('~', lookup('env', 'HOME')) }} && \
touch {{ vm_images_dir }}/{{ vm_name }}.customized
become: yes
args:
creates: "{{ vm_images_dir }}/{{ vm_name }}.customized"
- name: Provision VM using virt-install
shell: |
virt-install \
@@ -64,7 +53,8 @@
--network network=default \
--graphics none \
--noautoconsole \
--boot uefi
--boot uefi \
--cloud-init user-data=/tmp/{{ vm_name }}_user-data
args:
creates: "/etc/libvirt/qemu/{{ vm_name }}.xml"
become: yes