Page MenuHomePhorge

No OneTemporary

Authored By
Unknown
Size
15 KB
Referenced Files
None
Subscribers
None
diff --git a/deployments/ansible/roles/ansible-role-drbd/tasks/main.yml b/deployments/ansible/roles/ansible-role-drbd/tasks/main.yml
index 0920b3b..61054c5 100644
--- a/deployments/ansible/roles/ansible-role-drbd/tasks/main.yml
+++ b/deployments/ansible/roles/ansible-role-drbd/tasks/main.yml
@@ -1,55 +1,56 @@
---
- name: Validate drbd_devices structure
ansible.builtin.assert:
that:
- drbd_devices is defined
fail_msg: "drbd_devices must be a non-empty list. Current value: {{ drbd_devices }}"
# This turns a simple:
# - backing_device: /dev/vg_drbd/lv_amavis_drbd
# name: "amavis"
# device: /dev/drbd1
# port: 7791
# into:
# - backing_device: /dev/vg_drbd/lv_amavis_drbd
# device: /dev/drbd1
# name: "drbd_amavis"
# primary_host: worker1.kolab.ait-msp-infra.net
# secondary_host: worker2.kolab.ait-msp-infra.net
# mountpoint: /data/amavis
- name: Turn drdb_simple into drdb configuration
ansible.builtin.set_fact:
drbd: >-
{%- set drbd = [] -%}
{%- for item in drbd_devices -%}
{%- set _ = drbd.append({
- 'primary_backing_device': item.primary_backing_device | default( item.backing_device ),
- 'secondary_backing_device': item.secondary_backing_device | default( item.backing_device ),
+ 'backing_device': item.backing_device | default( omit ),
+ 'primary_backing_device': item.primary_backing_device | default( omit ),
+ 'secondary_backing_device': item.secondary_backing_device | default( omit ),
'device': item.device,
'name': 'drbd_' + item.name,
'port': item.port,
'primary_host': drbd_primary_host,
'secondary_host': drbd_secondary_host,
'mountpoint': item.mountpoint
}) -%}
{%- endfor -%}
{{ drbd }}
when: drbd_devices is defined
- name: Install DRBD
ansible.builtin.include_tasks:
file: "{{ ansible_os_family }}.yml"
apply:
tags: ['drbd_install']
tags:
- drbd_install
- name: Configure DRBD
ansible.builtin.import_tasks:
file: drbd_config.yml
tags:
- drbd_config
- name: Validate the configuration of DRBD
ansible.builtin.command:
cmd: drbdadm dump all
diff --git a/deployments/ansible/roles/kvm/tasks/main.yml b/deployments/ansible/roles/kvm/tasks/main.yml
index 94e8c72..6833c0b 100644
--- a/deployments/ansible/roles/kvm/tasks/main.yml
+++ b/deployments/ansible/roles/kvm/tasks/main.yml
@@ -1,240 +1,240 @@
---
- name: Validate volumes structure
ansible.builtin.assert:
that:
- volumes is defined
fail_msg: "Volumes must be a non-empty list. Current value: {{ volumes }}"
- 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 | rejectattr('size', 'equalto', '0') | list | default([]) }}"
+ _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 }} console=ttyS0,115200n8 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 '' }}
--console pty,target_type=serial
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 | rejectattr('size', 'equalto', '0') | list | default([]) }}"
+ _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
diff --git a/deployments/k3s-replicated/ansible/group_vars/worker_nodes.yaml b/deployments/k3s-replicated/ansible/group_vars/worker_nodes.yaml
index 43d7cf6..9ca37e2 100644
--- a/deployments/k3s-replicated/ansible/group_vars/worker_nodes.yaml
+++ b/deployments/k3s-replicated/ansible/group_vars/worker_nodes.yaml
@@ -1,82 +1,86 @@
---
# Note: "virsh attach-device --target" doesn't actually enforce anything, which is why we rely on --serial and the thus generated /dev/disk/by-id/virtio-$name device
# We still need to provide a unique device target (it's just not honored always, making it largely useless)
-volumes:
+volumes: "{{ base_volumes + (ldap_enabled | default(false) | ternary([ldap_volume], [])) }}"
+base_volumes:
- name: amavis
pool: "{{ amavis_pool | default( data_pool ) }}"
size: "{{ amavis_size }}"
device: vdb
- name: imap
pool: "{{ imap_pool | default( data_pool ) }}"
size: "{{ imap_size }}"
device: vdc
- name: minio
pool: "{{ minio_pool | default( data_pool ) }}"
size: "{{ minio_size }}"
device: vdd
- name: postfix
pool: "{{ postfix_pool | default( data_pool ) }}"
size: "{{ postfix_size }}"
device: vde
- name: prometheus
pool: "{{ prometheus_pool | default( data_pool ) }}"
size: "{{ prometheus_size }}"
device: vdf
- name: imapmetadata
pool: "{{ imapmetadata_pool | default( data_pool) }}"
size: "{{ imapmetadata_size }}"
device: vdg
- - name: ldap
- pool: "{{ ldap_pool | default( data_pool) }}"
- size: "{{ ldap_size | default( 0 ) }}"
- device: vdh
- name: logs
pool: "{{ logs_pool | default( data_pool) }}"
size: "{{ logs_size }}"
device: vdi
+ldap_volume:
+ name: ldap
+ pool: "{{ ldap_pool | default( data_pool) }}"
+ size: "{{ ldap_size }}"
+ device: vdh
# We keep pushgateway on local disk
drbd_primary_host: "{{ groups['worker_nodes'][0] }}"
drbd_secondary_host: "{{ groups['worker_nodes'][1] }}"
-drbd_devices:
+drbd_devices: "{{ base_drbd_devices + (ldap_enabled | default(false) | ternary([ldap_device], [])) }}"
+base_drbd_devices:
- backing_device: /dev/disk/by-id/virtio-amavis
name: amavis
device: /dev/drbd1
port: 7791
mountpoint: /data/amavis
- backing_device: "{{ imap_drbd_backing_device | default( '/dev/disk/by-id/virtio-imap' ) }}"
- primary_backing_device: "{{ imap_drbd_primary_backing_device }}"
- secondary_backing_device: "{{ imap_drbd_secondary_backing_device }}"
+ primary_backing_device: "{{ imap_drbd_primary_backing_device | default( omit ) }}"
+ secondary_backing_device: "{{ imap_drbd_secondary_backing_device | default( omit ) }}"
name: imap
device: /dev/drbd2
port: 7792
mountpoint: /data/imap/spool
- backing_device: /dev/disk/by-id/virtio-minio
name: minio
device: /dev/drbd3
port: 7793
mountpoint: /data/minio
- backing_device: /dev/disk/by-id/virtio-postfix
name: postfix
device: /dev/drbd4
port: 7794
mountpoint: /data/postfix
- backing_device: /dev/disk/by-id/virtio-prometheus
name: prometheus
device: /dev/drbd5
port: 7795
mountpoint: /data/prometheus
- backing_device: "{{ imapmetadata_drbd_backing_device | default( '/dev/disk/by-id/virtio-imapmetadata' ) }}"
- primary_backing_device: "{{ imapmetadata_drbd_primary_backing_device }}"
- secondary_backing_device: "{{ imapmetadata_drbd_secondary_backing_device }}"
+ primary_backing_device: "{{ imapmetadata_drbd_primary_backing_device | default( omit ) }}"
+ secondary_backing_device: "{{ imapmetadata_drbd_secondary_backing_device | default( omit ) }}"
name: imapmetadata
device: /dev/drbd6
port: 7796
mountpoint: /data/imap/lib
- - backing_device: /dev/disk/by-id/virtio-ldap
- name: ldap
- device: /dev/drbd7
- port: 7797
- mountpoint: /data/ldap
+ldap_device:
+ backing_device: /dev/disk/by-id/virtio-ldap
+ name: ldap
+ device: /dev/drbd7
+ port: 7797
+ mountpoint: /data/ldap
disks:
- device: /dev/disk/by-id/virtio-logs
mountpoint: /data/logs/

File Metadata

Mime Type
text/x-diff
Expires
Sat, Apr 4, 3:25 AM (1 d, 18 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18822403
Default Alt Text
(15 KB)

Event Timeline