diff --git a/roles/compatcheck/meta/argument_specs.yaml b/roles/compatcheck/meta/argument_specs.yaml new file mode 100644 index 0000000..32ffb28 --- /dev/null +++ b/roles/compatcheck/meta/argument_specs.yaml @@ -0,0 +1,32 @@ +--- +argument_specs: + main: + short_description: Checks that the host is running a supported os + description: + - Checks that the host is runing a supported os. + - Supported distros and versions are defined by the compatcheck_supported_distros variable. + - This role is used by other roles to check compatibility. + options: + compatcheck_supported_distributions: + description: A list of distros and versions supported by the role. + type: list + required: true + elements: dict + options: + name: + description: Name of the distro, in lowercase + type: str + required: true + choices: + - debian + - ubuntu + - fedora + - archlinux + version_min: + description: Earliest supported major version. Allows any version if not specified. + type: int + required: false + version_max: + description: Last supported major version. Allows any version if not specified. + type: int + required: false diff --git a/roles/compatcheck/tasks/main.yaml b/roles/compatcheck/tasks/main.yaml new file mode 100644 index 0000000..00b151f --- /dev/null +++ b/roles/compatcheck/tasks/main.yaml @@ -0,0 +1,15 @@ +--- +- name: Fail if distribution not supported + ansible.builtin.fail: + msg: "{{ lookup('ansible.builtin.template', 'distroerror.j2').strip() }}" + when: checkfailed + loop: + - "{{ compatcheck_distro | length == 0 }}" + - > + {{ + ansible_distribution_major_version != 'n/a' and + compatcheck_distro[0].version_min | default(0) > ansible_distribution_major_version | int + }} + - "{{ compatcheck_distro[0].version_max is defined and compatcheck_distro[0].version_max < ansible_distribution_major_version | int }}" + loop_control: + loop_var: checkfailed diff --git a/roles/compatcheck/templates/distroerror.j2 b/roles/compatcheck/templates/distroerror.j2 new file mode 100644 index 0000000..6cdf723 --- /dev/null +++ b/roles/compatcheck/templates/distroerror.j2 @@ -0,0 +1,15 @@ +{%- set distros = [] -%} +{%- for distro in compatcheck_supported_distributions -%} + {%- if distro.version_min is defined -%} + {%- if distro.version_max is defined -%} + {{ distros.append(distro.name | capitalize + ' ' + distro.version_min | string + '-' + distro.version_max | string) }} + {%- else -%} + {{ distros.append(distro.name | capitalize + ' ' + distro.version_min | string + '+') }} + {%- endif -%} + {%- elif distro.version_max is defined -%} + {{ distros.append(distro.name | capitalize + ' <' + distro.version_max | string) }} + {%- else -%} + {{ distros.append(distro.name | capitalize) }} + {%- endif -%} +{%- endfor -%} +This role only supports {{ distros | join(', ') }} (You are running {{ ansible_distribution }} {{ ansible_distribution_major_version }}) diff --git a/roles/compatcheck/vars/main.yaml b/roles/compatcheck/vars/main.yaml new file mode 100644 index 0000000..b20da70 --- /dev/null +++ b/roles/compatcheck/vars/main.yaml @@ -0,0 +1,2 @@ +--- +compatcheck_distro: "{{ compatcheck_supported_distributions | selectattr('name', 'equalto', ansible_distribution | lower) }}"