From 35b0422e541aef016cbed7e9ef5e3c4d3b56b22a Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Fri, 19 Apr 2024 23:19:24 +0100 Subject: [PATCH] new system requires checks --- molecule/absent/verify.yml | 34 +++++++++++++++--------- molecule/cloud/converge.yml | 1 - molecule/cloud/verify.yml | 42 ++++++++++++++++++------------ molecule/local/converge.yml | 6 +++++ molecule/local/molecule.yml | 18 +++++++++++++ molecule/local/verify.yml | 32 +++++++++++++++++++++++ molecule/static-build/converge.yml | 1 - molecule/static-build/verify.yml | 42 ++++++++++++++++++------------ tasks/distro-requirements.yml | 26 ++++++++++++++++++ tasks/main.yml | 3 +++ vars/main.yml | 13 +++++++++ 11 files changed, 169 insertions(+), 49 deletions(-) create mode 100644 molecule/local/converge.yml create mode 100644 molecule/local/molecule.yml create mode 100644 molecule/local/verify.yml create mode 100644 tasks/distro-requirements.yml create mode 100644 vars/main.yml diff --git a/molecule/absent/verify.yml b/molecule/absent/verify.yml index da52fb7..81648fe 100644 --- a/molecule/absent/verify.yml +++ b/molecule/absent/verify.yml @@ -3,18 +3,26 @@ hosts: all gather_facts: false tasks: - - name: "Get service facts" - ansible.builtin.service_facts: + - name: "Check if /tmp/unsupported_distro file exists" + ansible.builtin.stat: + path: "/tmp/unsupported_distro" + register: unsupported_distro_file - - name: "Check netdata service is stopped" - ansible.builtin.fail: - msg: "Netdata service is started" - when: "'netdata' in services and services['netdata']['state'] == 'started'" + - name: "Verify" + when: not unsupported_distro_file.stat.exists + block: + - name: "Get service facts" + ansible.builtin.service_facts: - - name: "Check netdata dashboard port to closed" - ansible.builtin.wait_for: - host: "{{ inventory_hostname }}" - port: "19999" - state: stopped - delay: 5 - timeout: 10 + - name: "Check netdata service is stopped" + ansible.builtin.fail: + msg: "Netdata service is started" + when: "'netdata' in services and services['netdata']['state'] == 'started'" + + - name: "Check netdata dashboard port to closed" + ansible.builtin.wait_for: + host: "{{ inventory_hostname }}" + port: "19999" + state: stopped + delay: 5 + timeout: 10 diff --git a/molecule/cloud/converge.yml b/molecule/cloud/converge.yml index 3fbdec4..0243527 100644 --- a/molecule/cloud/converge.yml +++ b/molecule/cloud/converge.yml @@ -2,7 +2,6 @@ - name: "Converge" hosts: all gather_facts: false - become: false vars: netdata_cloud_enable: true netdata_cloud_claim_token: this-is-a-test-token diff --git a/molecule/cloud/verify.yml b/molecule/cloud/verify.yml index 7911d53..0d0cae4 100644 --- a/molecule/cloud/verify.yml +++ b/molecule/cloud/verify.yml @@ -3,23 +3,31 @@ hosts: all gather_facts: false tasks: - - name: "Get service facts" - ansible.builtin.service_facts: + - name: "Check if /tmp/unsupported_distro file exists" + ansible.builtin.stat: + path: "/tmp/unsupported_distro" + register: unsupported_distro_file - - name: "Check netdata service is started" - ansible.builtin.fail: - msg: "netdata service is not started" - when: "'netdata' in services and services['netdata']['state'] != 'running'" + - name: "Verify" + when: not unsupported_distro_file.stat.exists + block: + - name: "Get service facts" + ansible.builtin.service_facts: - - name: "Check netdata service is enabled" - ansible.builtin.fail: - msg: "netdata service is not enabled" - when: "'netdata' in services and services['netdata.service']['status'] != 'enabled'" + - name: "Check netdata service is started" + ansible.builtin.fail: + msg: "netdata service is not started" + when: "'netdata' in services and services['netdata']['state'] != 'running'" - - name: "Check netdata dashboard port to closed" - ansible.builtin.wait_for: - host: "{{ inventory_hostname }}" - port: "19999" - state: stopped - delay: 5 - timeout: 10 + - name: "Check netdata service is enabled" + ansible.builtin.fail: + msg: "netdata service is not enabled" + when: "'netdata' in services and services['netdata.service']['status'] != 'enabled'" + + - name: "Check netdata dashboard port to closed" + ansible.builtin.wait_for: + host: "{{ inventory_hostname }}" + port: "19999" + state: stopped + delay: 5 + timeout: 10 diff --git a/molecule/local/converge.yml b/molecule/local/converge.yml new file mode 100644 index 0000000..2834ad3 --- /dev/null +++ b/molecule/local/converge.yml @@ -0,0 +1,6 @@ +--- +- name: "Converge" + hosts: all + gather_facts: false + roles: + - role: "dgibbs64.netdata" diff --git a/molecule/local/molecule.yml b/molecule/local/molecule.yml new file mode 100644 index 0000000..65cf92e --- /dev/null +++ b/molecule/local/molecule.yml @@ -0,0 +1,18 @@ +--- +dependency: + name: galaxy +driver: + name: docker +platforms: + - name: "${MOLECULE_IMAGE:-ubuntu2204}" + image: "geerlingguy/docker-${MOLECULE_IMAGE:-ubuntu2204}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + privileged: true + pre_build_image: true + cgroupns_mode: host +provisioner: + name: ansible +verifier: + name: ansible diff --git a/molecule/local/verify.yml b/molecule/local/verify.yml new file mode 100644 index 0000000..6c4efcc --- /dev/null +++ b/molecule/local/verify.yml @@ -0,0 +1,32 @@ +- name: "Verify" + hosts: all + gather_facts: false + tasks: + - name: "Check if /tmp/unsupported_distro file exists" + ansible.builtin.stat: + path: "/tmp/unsupported_distro" + register: unsupported_distro_file + + - name: "Verify" + when: not unsupported_distro_file.stat.exists + block: + - name: "Get service facts" + ansible.builtin.service_facts: + + - name: "Check netdata service is started" + ansible.builtin.fail: + msg: "netdata service is not started" + when: "'netdata' in services and services['netdata']['state'] != 'running'" + + - name: "Check netdata service is enabled" + ansible.builtin.fail: + msg: "netdata service is not enabled" + when: "'netdata' in services and services['netdata.service']['status'] != 'enabled'" + + - name: "Check netdata dashboard port to open" + ansible.builtin.wait_for: + host: "{{ inventory_hostname }}" + port: "19999" + state: started + delay: 5 + timeout: 10 diff --git a/molecule/static-build/converge.yml b/molecule/static-build/converge.yml index dc0288a..2834ad3 100644 --- a/molecule/static-build/converge.yml +++ b/molecule/static-build/converge.yml @@ -2,6 +2,5 @@ - name: "Converge" hosts: all gather_facts: false - become: false roles: - role: "dgibbs64.netdata" diff --git a/molecule/static-build/verify.yml b/molecule/static-build/verify.yml index 8d4863d..651ba9d 100644 --- a/molecule/static-build/verify.yml +++ b/molecule/static-build/verify.yml @@ -3,23 +3,31 @@ hosts: all gather_facts: false tasks: - - name: "Get service facts" - ansible.builtin.service_facts: + - name: "Check if /tmp/unsupported_distro file exists" + ansible.builtin.stat: + path: "/tmp/unsupported_distro" + register: unsupported_distro_file - - name: "Check netdata service is started" - ansible.builtin.fail: - msg: "netdata service is not started" - when: "'netdata' in services and services['netdata']['state'] != 'running'" + - name: "Verify" + when: not unsupported_distro_file.stat.exists + block: + - name: "Get service facts" + ansible.builtin.service_facts: - - name: "Check netdata service is enabled" - ansible.builtin.fail: - msg: "netdata service is not enabled" - when: "'netdata' in services and services['netdata.service']['status'] != 'enabled'" + - name: "Check netdata service is started" + ansible.builtin.fail: + msg: "netdata service is not started" + when: "'netdata' in services and services['netdata']['state'] != 'running'" - - name: "Check netdata dashboard port to open" - ansible.builtin.wait_for: - host: "{{ inventory_hostname }}" - port: "19999" - state: started - delay: 5 - timeout: 10 + - name: "Check netdata service is enabled" + ansible.builtin.fail: + msg: "netdata service is not enabled" + when: "'netdata' in services and services['netdata.service']['status'] != 'enabled'" + + - name: "Check netdata dashboard port to open" + ansible.builtin.wait_for: + host: "{{ inventory_hostname }}" + port: "19999" + state: started + delay: 5 + timeout: 10 diff --git a/tasks/distro-requirements.yml b/tasks/distro-requirements.yml new file mode 100644 index 0000000..3db1b49 --- /dev/null +++ b/tasks/distro-requirements.yml @@ -0,0 +1,26 @@ +--- +- name: "Check if distro or architecture are supported" + ansible.builtin.set_fact: + distro_supported: false + when: > + supported_distros | selectattr("name", "equalto", ansible_distribution) | list | length == 0 or + ansible_distribution_version is version(supported_distros | selectattr("name", "equalto", ansible_distribution) | map(attribute="min_version") | first, "<") or + ansible_architecture not in (supported_distros | selectattr("name", "equalto", ansible_distribution) | map(attribute="supported_architectures", default=[]) | first) + +- name: "Check if distro or architecture are supported" + ansible.builtin.debug: + msg: "{{ ansible_distribution }} {{ ansible_distribution_version }} on {{ ansible_architecture }} is not supported" + when: distro_supported is false + +# For molecule testing only +- name: "Create file if distro is not supported" + ansible.builtin.copy: + dest: "/tmp/unsupported_distro" + content: "unsupported" + mode: "0644" + no_log: true + when: distro_supported is false and "molecule-notest" in ansible_skip_tags + +- name: "Skip role if distro or architecture is not supported" + ansible.builtin.meta: end_play + when: distro_supported is false diff --git a/tasks/main.yml b/tasks/main.yml index bd4f900..f7df30e 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -14,6 +14,9 @@ ansible.builtin.import_tasks: assert-all.yml delegate_to: localhost +- name: "Distro Requirements" + ansible.builtin.include_tasks: distro-requirements.yml + - name: "Become block" become: true block: diff --git a/vars/main.yml b/vars/main.yml new file mode 100644 index 0000000..5e13e2e --- /dev/null +++ b/vars/main.yml @@ -0,0 +1,13 @@ +--- +supported_distros: + - { name: "AlmaLinux", min_version: "8", supported_architectures: "['x86_64', 'aarch64']" } + - { name: "Amazon", min_version: "2023", supported_architectures: "['x86_64', 'aarch64']" } + - { name: "CentOS", min_version: "7", supported_architectures: "['x86_64']" } + - { name: "Debian", min_version: "10", supported_architectures: "['x86_64', 'i686', 'aarch64', 'armv7l']" } + - { name: "Fedora", min_version: "37", supported_architectures: "['x86_64', 'aarch64']" } + - { name: "openSUSE Leap", min_version: "15.4", supported_architectures: "['x86_64', 'aarch64']" } + - { name: "openSUSE Tumbleweed", min_version: "", supported_architectures: "['x86_64', 'aarch64']" } + - { name: "OracleLinux", min_version: "8", supported_architectures: "['x86_64', 'aarch64']" } + - { name: "RedHat", min_version: "8", supported_architectures: "['x86_64', 'aarch64']" } + - { name: "Suse", min_version: "15.2", supported_architectures: "['x86_64', 'aarch64']" } + - { name: "Ubuntu", min_version: "20.04", supported_architectures: "['x86_64', 'i686', 'armv7l']" }