---
- name: OS | Fail if hostname is invalid
  assert:
    that: .hostname | regexMatch "^[a-z0-9]([a-z0-9-]*[a-z0-9])?(\\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)*$"
    fail_msg: >-
      The hostname "{{ .hostname }}" is invalid. Hostnames must use only lowercase alphanumeric characters, '.', or '-', and must start and end with an alphanumeric character.

- name: OS | Fail if operating system is not supported
  assert:
    that: or (.cluster_require.allow_unsupported_distribution_setup) (.cluster_require.supported_os_distributions | has .os.release.ID)
    fail_msg: >-
      The operating system "{{ .os.release.ID }}" is not recognized or supported.

- name: OS | Fail if architecture is not supported
  assert:
    that: .cluster_require.supported_architectures | has .os.architecture
    fail_msg: >-
      The system architecture "{{ .os.architecture }}" is not supported.

- name: OS | Fail if master node memory is insufficient
  assert:
    that: .process.memInfo.MemTotal | trimSuffix " kB" | atoi | le .cluster_require.minimal_master_memory_mb
  when: .groups.kube_control_plane | default list | has .inventory_hostname

- name: OS | Fail if worker node memory is insufficient
  assert:
    that: .process.memInfo.MemTotal | trimSuffix " kB" | atoi | le .cluster_require.minimal_node_memory_mb
  when:
    - .groups.kube_worker | default list | has .inventory_hostname

- name: OS | Fail if kernel version is too old
  assert:
    that: .os.kernel_version | splitList "-" | first | semverCompare (printf ">=%s" .cluster_require.min_kernel_version)
    fail_msg: >-
      The kernel version "{{ .os.kernel_version }}" is too old. Minimum required version: {{ .cluster_require.min_kernel_version }}.
