Page MenuHomePhorge

No OneTemporary

Authored By
Unknown
Size
9 KB
Referenced Files
None
Subscribers
None
diff --git a/deployments/ansible/roles/kolab/defaults/main.yaml b/deployments/ansible/roles/kolab/defaults/main.yaml
index 2339a0c..ccb1fb6 100644
--- a/deployments/ansible/roles/kolab/defaults/main.yaml
+++ b/deployments/ansible/roles/kolab/defaults/main.yaml
@@ -1,4 +1,5 @@
---
disable_cert_manager: false
disable_ingress: false
skip_reconfigure: false
+production: false
diff --git a/deployments/ansible/roles/kvm/defaults/main.yaml b/deployments/ansible/roles/kvm/defaults/main.yaml
index dcec8b4..b152104 100644
--- a/deployments/ansible/roles/kvm/defaults/main.yaml
+++ b/deployments/ansible/roles/kvm/defaults/main.yaml
@@ -1,6 +1,7 @@
---
vm_disk_size: 20G
vm_cpus: 2
vm_memory: 3G
recreate_vm: false
vm_pool: default
+use_kickstart_file: false
diff --git a/deployments/ansible/roles/kvm/tasks/main.yml b/deployments/ansible/roles/kvm/tasks/main.yml
index 6010803..5fab651 100644
--- a/deployments/ansible/roles/kvm/tasks/main.yml
+++ b/deployments/ansible/roles/kvm/tasks/main.yml
@@ -1,232 +1,233 @@
---
- name: Destroy
community.libvirt.virt:
name: "{{ inventory_hostname }}"
uri: "{{ qemu_uri }}"
command: destroy
ignore_errors: true
when: recreate_vm
delegate_to: 127.0.0.1
- name: Delete disk
command: virsh --connect {{ qemu_uri }} vol-delete --pool {{ vm_pool }} guest_{{ inventory_hostname }}
ignore_errors: true
when: recreate_vm
delegate_to: 127.0.0.1
- name: Undefine
community.libvirt.virt:
name: "{{ inventory_hostname }}"
uri: "{{ qemu_uri }}"
command: undefine
ignore_errors: true
when: recreate_vm
delegate_to: 127.0.0.1
- name: Prepare data volumes
vars:
_volumes: "{{ volumes | default([]) }}"
block:
- name: Check for data volume to create
command: virsh --connect {{ qemu_uri }} vol-info --pool {{ item['pool'] }} data_{{ inventory_hostname }}_{{ item['name'] }}
delegate_to: 127.0.0.1
register: _disk_info
ignore_errors: true
loop: "{{ _volumes }}"
- name: Create data volume if missing
command: virsh --connect {{ qemu_uri }} vol-create-as --pool {{ item.item['pool'] }} --name data_{{ inventory_hostname }}_{{ item.item['name'] }} --capacity {{ item.item['size'] }}
delegate_to: 127.0.0.1
when: item.rc == 1
loop: "{{ _disk_info.results | from_yaml | list}}"
- name: Get VM status
command: virsh --connect {{ qemu_uri }} domstate {{ inventory_hostname }}
ignore_errors: true
register: _vm_status
delegate_to: 127.0.0.1
- name: VM Status
debug:
msg: "VM {{ inventory_hostname }} is {{ _vm_status.stdout | default('not defined, will create it' ) }}"
# VM create block start
- name: VM create
when: _vm_status is failed
vars:
_vm_pool: "{{ vm_pool }}"
block:
- name: Upload vm image
when: not use_kickstart_file
block:
- name: Check for kolab-minimal disk image
command: virsh --connect {{ qemu_uri }} vol-info --pool {{ _vm_pool }} kolab-minimal
delegate_to: 127.0.0.1
register: _disk_info
ignore_errors: true
- name: Download vm image
get_url:
url: "{{ disk_image }}"
dest: "/tmp/{{ ansible_user }}"
owner: "{{ ansible_user }}"
register: downloaded_file
delegate_to: 127.0.0.1
when: not disk_image_path
- ansible.builtin.set_fact:
disk_image_path: "{{ downloaded_file.dest }}"
when: not disk_image_path
# Size according to qemu-img info --output json ../../build/packer/artifacts/qemu/kolab-minimal-0.1/kolab-minimal-0.1.qcow2 | jq -r .[\"virtual-size\"]
- name: Create kolab-minimal Volume
command: virsh --connect {{ qemu_uri }} vol-create-as --pool {{ _vm_pool }} --name kolab-minimal --capacity 20G --format qcow2
delegate_to: 127.0.0.1
when: _disk_info is failed
# This can fail because it's executed per host, so with multiple hosts on the same hypervisor it will be redundant
ignore_errors: true
- name: Upload kolab-minimal image
command: virsh --connect {{ qemu_uri }} vol-upload --pool {{ _vm_pool }} --vol kolab-minimal --file {{ disk_image_path }}
delegate_to: 127.0.0.1
when: _disk_info is failed
# This can fail because it's executed per host, so with multiple hosts on the same hypervisor it will be redundant
ignore_errors: true
- name: Create VM Volume
command: virsh --connect {{ qemu_uri }} vol-clone --pool {{ _vm_pool }} --vol kolab-minimal --newname guest_{{ inventory_hostname }}
delegate_to: 127.0.0.1
- name: Prepare kickstart file
when: use_kickstart_file
block:
- name: Create kickstart file for VM installation
delegate_to: 127.0.0.1
template:
src: "almalinux9.ks.j2"
dest: "/tmp/{{ vm_hostname | default(inventory_hostname) }}.ks"
mode: '666'
vars:
_vm_root_password: "{{ vm_root_password }}"
root_ssh_pubkeys: "{{ vm_root_ssh_pubkeys }}"
_vm_users: "{{ vm_users }}"
_hostname: "{{ vm_hostname | default(inventory_hostname) }}"
_install_url: "{{ install_url }}"
register: _r_kickstart
- name: Check for volume
command: virsh --connect {{ qemu_uri }} vol-info --pool {{ _vm_pool }} guest_{{ inventory_hostname }}
delegate_to: 127.0.0.1
register: _disk_info
ignore_errors: true
- name: Create VM Volume
command: virsh --connect {{ qemu_uri }} vol-create-as --pool {{ _vm_pool }} --name guest_{{ inventory_hostname }} --capacity {{ vm_disk_size }}
delegate_to: 127.0.0.1
when: _disk_info is failed
- name: Create VM with virt-install
shell:
# We start off with a fixed amount of memory because the format is different.
# Also, not having enough memory results in rather cryptic installation errors (dracut: FATAL: Failed to find a root filesystem in /tmp/curl_fetch_url1/install.img).
# We also postpone attaching the data disks.
cmd: >
virt-install
--connect {{ qemu_uri }}
--name {{ vm_hostname | default(inventory_hostname) }}
--virt-type kvm
--vcpus {{ vm_cpus }}
--memory 4096
--boot hd,menu=on
{% if use_kickstart_file %}
--initrd-inject={{ _r_kickstart['dest'] }}
--extra-args="inst.ks=file:/{{ _r_kickstart['dest'] | basename }} SERVERNAME={{ vm_hostname | default(inventory_hostname) }} ip=dhcp"
--location {{ install_url }}
{% else %}
--import
{% endif %}
--disk vol={{ _vm_pool }}/guest_{{ inventory_hostname }},bus=virtio
--network {{ vm_network | default('type=network,source=default,model=virtio') }}
--os-variant almalinux9
--noreboot
--graphics none {{ '--dry-run' if ansible_check_mode else '' }}
chdir: "{{ resources_dir }}"
delegate_to: 127.0.0.1
- name: Wait for VM installation completion
command:
cmd: >-
virsh
--connect {{ qemu_uri }}
domstate "{{ inventory_hostname }}"
check_mode: false
delay: 30
register: _vm_state
retries: 30
until: _vm_state.stdout == "shut off"
delegate_to: 127.0.0.1
- name: Remove kickstart file
file:
path: "{{ _r_kickstart['dest'] }}"
state: absent
delegate_to: 127.0.0.1
+ when: use_kickstart_file
# VM create block end
- name: Print return information from the previous task
ansible.builtin.debug:
var: _vm_status
- name: Attach data volumes
vars:
_volumes: "{{ volumes | default([]) }}"
block:
- name: Check for data volume to attach
command: virsh --connect {{ qemu_uri }} vol-path --pool {{ item['pool'] }} data_{{ inventory_hostname }}_{{ item['name'] }}
delegate_to: 127.0.0.1
register: _disk_info
loop: "{{ _volumes }}"
- name: Check for existing devices
command: virsh --connect {{ qemu_uri }} domblklist {{ inventory_hostname }}
delegate_to: 127.0.0.1
register: _device_info
- name: Attach volume if not already attached
command: virsh --connect {{ qemu_uri }} attach-disk --domain {{ inventory_hostname }} --source {{ item.stdout }} --target {{ item.item['device'] }} --targetbus virtio --driver qemu --subdriver raw --serial {{ item.item['name'] }} --config --persistent
delegate_to: 127.0.0.1
when: _disk_info and item.stdout not in _device_info.stdout
loop: "{{ _disk_info.results }}"
- name: Set max memory
shell: virsh --connect {{ qemu_uri }} setmaxmem {{ inventory_hostname }} {{ vm_max_memory | default(vm_memory) }} --config
delegate_to: 127.0.0.1
- name: Set memory
shell: virsh --connect {{ qemu_uri }} setmem {{ inventory_hostname }} {{ vm_memory }} --config
delegate_to: 127.0.0.1
- name: Set max cpu
shell: virsh --connect {{ qemu_uri }} setvcpus {{ inventory_hostname }} {{ vm_cpus }} --maximum --config
delegate_to: 127.0.0.1
- name: Set cpu
shell: virsh --connect {{ qemu_uri }} setvcpus {{ inventory_hostname }} {{ vm_cpus }} --config
delegate_to: 127.0.0.1
- name: start vm
when: _vm_status.stdout != 'running'
community.libvirt.virt:
name: "{{ inventory_hostname }}"
state: running
uri: "{{ qemu_uri }}"
delegate_to: 127.0.0.1
- name: Discover vm ip
shell: virsh --connect {{ qemu_uri }} domifaddr {{ inventory_hostname }} --source agent | grep eth0 | grep ipv4 | head -1 | tr -s ' ' | cut -d ' ' -f5 | cut -d '/' -f1
register: vm_ip
retries: 50
delay: 2
until: vm_ip.stdout != ""
delegate_to: 127.0.0.1
check_mode: false

File Metadata

Mime Type
text/x-diff
Expires
Sat, Apr 4, 3:21 AM (1 d, 7 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18822384
Default Alt Text
(9 KB)

Event Timeline