---
- name: Stop if bad hostname
  assert:
    that: .hostname | regexMatch "^[a-z0-9]([a-z0-9-]*[a-z0-9])?(\\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)*$"
    fail_msg: >-
      "Hostname must consist of lower case alphanumeric characters, '.' or '-', and must start and end with an alphanumeric character"

- name: Stop if the os does not support
  assert:
    that: or (.cluster_require.allow_unsupported_distribution_setup) (.cluster_require.supported_os_distributions | has .os.release.ID)
    fail_msg: "{{ .os.release.ID }} is not a known OS"

- name: Stop if arch supported
  assert:
    that: .cluster_require.supported_architectures | has .os.architecture
    fail_msg: "{{ .os.architecture }} is not a known arch"

- name: Stop if memory is too small for masters
  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: Stop if memory is too small for nodes
  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: Stop if kernel version is too low
  assert:
    that: .os.kernel_version | splitList "-" | first | semverCompare (printf ">=%s" .cluster_require.min_kernel_version)
    fail_msg: >-
      "kernel version: {{ .os.kernel_version }} is too low, required at least: {{ .cluster_require.min_kernel_version }} "
