diff --git a/roles/infra/templates/outputs.tf.j2 b/roles/infra/templates/outputs.tf.j2 index d1cc8cf2d..542e8c6cc 100644 --- a/roles/infra/templates/outputs.tf.j2 +++ b/roles/infra/templates/outputs.tf.j2 @@ -32,7 +32,7 @@ output "cluster_nodes" { {% endfor %} ] facts = { - k3s_storage_device = openstack_compute_volume_attach_v2.data_volume_attach.device + k3s_storage_volume_id = openstack_compute_volume_attach_v2.data_volume_attach.volume_id # Set the gateway IP as a fact that can be consumed {% if not infra_provisioning_network_id and infra_use_floatingip %} diff --git a/roles/k3s/defaults/main.yml b/roles/k3s/defaults/main.yml index bc1696802..dc8ecb00a 100644 --- a/roles/k3s/defaults/main.yml +++ b/roles/k3s/defaults/main.yml @@ -7,7 +7,6 @@ k3s_binary_checksum_url: "{{ k3s_repo }}/releases/download/{{ k3s_version }}/sha k3s_binary_checksum: "sha256:{{ lookup('url', k3s_binary_checksum_url, wantlist=True) | first | split | first }}" # Settings for an additional block device that will hold the k3s state, if present -k3s_storage_device: /dev/sdb k3s_storage_fstype: xfs # Indicates if the Traefik ingress controller should be enabled diff --git a/roles/k3s/tasks/main.yml b/roles/k3s/tasks/main.yml index 93154878f..c6de71839 100644 --- a/roles/k3s/tasks/main.yml +++ b/roles/k3s/tasks/main.yml @@ -1,13 +1,41 @@ --- -- name: Check if k3s storage device is attached - ansible.builtin.stat: - path: "{{ k3s_storage_device }}" - register: k3s_storage_device_stat - -- name: Fail if k3s storage device is missing - ansible.builtin.fail: - msg: "K3s storage device not found at {{ k3s_storage_device }}" - when: not k3s_storage_device_stat.stat.exists +- name: Find the block device for the k3s storage volume + block: + - name: Stat candidate device paths + ansible.builtin.stat: + path: "/dev/disk/by-id/{{ item }}" + loop: + # KVM + - "{{ 'virtio-{}'.format(k3s_storage_volume_id[:20]) }}" + # KVM #852 + - "{{ 'virtio-{}'.format(k3s_storage_volume_id) }}" + # KVM virtio-scsi + - "{{ 'scsi-0QEMU_QEMU_HARDDISK_{}'.format(k3s_storage_volume_id[:20]) }}" + # KVM virtio-scsi #852 + - "{{ 'scsi-0QEMU_QEMU_HARDDISK_{}'.format(k3s_storage_volume_id) }}" + # ESXi + - "{{ 'wwn-0x{}'.format(k3s_storage_volume_id | replace('-', '')) }}" + register: candidate_device_paths_stat + + - name: Set volume block device name + ansible.builtin.set_fact: + k3s_storage_device: >- + /dev/{{ + candidate_device_paths_stat.results | + selectattr("stat.exists") | + map(attribute = "stat.lnk_source") | + first | + default("") | + trim("/") | + split("/") | + last + }} + + - name: Fail if block device was not found + ansible.builtin.fail: + msg: "Could not locate block device for volume {{ k3s_storage_volume_id }}." + when: k3s_storage_device == "/dev/" + - name: Ensure filesystem exists on storage device community.general.filesystem: