From d274b3a56cd010ee20b22f48ff4258388486a740 Mon Sep 17 00:00:00 2001 From: Rich Megginson Date: Tue, 31 Oct 2023 10:20:18 -0600 Subject: [PATCH] feat: support for ostree systems Feature: Allow running and testing the role with ostree managed nodes. Reason: We have users who want to use the role to manage ostree systems. Result: Users can use the role to manage ostree managed nodes. Signed-off-by: Rich Megginson --- .ansible-lint | 2 + .ostree/README.md | 3 + .ostree/get_ostree_data.sh | 123 ++++++++++++++++++ .ostree/packages-runtime-CentOS-8.txt | 5 + .ostree/packages-runtime-Fedora.txt | 10 ++ .ostree/packages-runtime-RedHat-8.txt | 9 ++ .ostree/packages-runtime-RedHat-9.txt | 9 ++ .ostree/packages-runtime.txt | 6 + .ostree/packages-testing-CentOS-8.txt | 5 + .ostree/packages-testing-CentOS.txt | 6 + .ostree/packages-testing-Fedora.txt | 17 +++ .ostree/packages-testing-RedHat-6.txt | 4 + .ostree/packages-testing-RedHat-7.txt | 6 + .ostree/packages-testing-RedHat-8.txt | 16 +++ .ostree/packages-testing-RedHat-9.txt | 16 +++ .ostree/packages-testing.txt | 2 + .ostree/roles-runtime.txt | 2 + .sanity-ansible-ignore-2.12.txt | 1 + .sanity-ansible-ignore-2.13.txt | 1 + .sanity-ansible-ignore-2.14.txt | 1 + .sanity-ansible-ignore-2.15.txt | 1 + .sanity-ansible-ignore-2.9.txt | 1 + README-ostree.md | 66 ++++++++++ README.md | 8 +- meta/collection-requirements.yml | 2 + tasks/main.yml | 24 ++++ tests/check_into_elasticsearch.yml | 3 +- tests/tests_verify_from_elasticsearch.yml | 12 +- tests/tests_verify_mssql.yml | 18 +++ tests/tests_verify_postfix.yml | 18 +++ vars/main.yml | 12 ++ .../roles/elasticsearch/tasks/main.yml | 14 ++ 32 files changed, 416 insertions(+), 7 deletions(-) create mode 100644 .ostree/README.md create mode 100755 .ostree/get_ostree_data.sh create mode 100644 .ostree/packages-runtime-CentOS-8.txt create mode 100644 .ostree/packages-runtime-Fedora.txt create mode 100644 .ostree/packages-runtime-RedHat-8.txt create mode 100644 .ostree/packages-runtime-RedHat-9.txt create mode 100644 .ostree/packages-runtime.txt create mode 100644 .ostree/packages-testing-CentOS-8.txt create mode 100644 .ostree/packages-testing-CentOS.txt create mode 100644 .ostree/packages-testing-Fedora.txt create mode 100644 .ostree/packages-testing-RedHat-6.txt create mode 100644 .ostree/packages-testing-RedHat-7.txt create mode 100644 .ostree/packages-testing-RedHat-8.txt create mode 100644 .ostree/packages-testing-RedHat-9.txt create mode 100644 .ostree/packages-testing.txt create mode 100644 .ostree/roles-runtime.txt create mode 100644 .sanity-ansible-ignore-2.12.txt create mode 100644 .sanity-ansible-ignore-2.13.txt create mode 100644 .sanity-ansible-ignore-2.14.txt create mode 100644 .sanity-ansible-ignore-2.15.txt create mode 100644 .sanity-ansible-ignore-2.9.txt create mode 100644 README-ostree.md diff --git a/.ansible-lint b/.ansible-lint index a5e96ab..da66d5f 100644 --- a/.ansible-lint +++ b/.ansible-lint @@ -32,3 +32,5 @@ mock_roles: - performancecopilot.metrics.redis - performancecopilot.metrics.repository - performancecopilot.metrics.spark +mock_modules: + - ansible.utils.update_fact diff --git a/.ostree/README.md b/.ostree/README.md new file mode 100644 index 0000000..f5e6931 --- /dev/null +++ b/.ostree/README.md @@ -0,0 +1,3 @@ +*NOTE*: The `*.txt` files are used by `get_ostree_data.sh` to create the lists +of packages, and to find other system roles used by this role. DO NOT use them +directly. diff --git a/.ostree/get_ostree_data.sh b/.ostree/get_ostree_data.sh new file mode 100755 index 0000000..7c32524 --- /dev/null +++ b/.ostree/get_ostree_data.sh @@ -0,0 +1,123 @@ +#!/bin/bash + +set -euo pipefail + +role_collection_dir="${ROLE_COLLECTION_DIR:-fedora/linux_system_roles}" +ostree_dir="${OSTREE_DIR:-"$(dirname "$(realpath "$0")")"}" + +if [ -z "${4:-}" ] || [ "${1:-}" = help ] || [ "${1:-}" = -h ]; then + cat < 0 + +- name: Ensure correct package manager for ostree systems + vars: + ostree_pkg_mgr: ansible.posix.rhel_rpm_ostree + ostree_booted_file: /run/ostree-booted + when: ansible_facts.pkg_mgr | d("") != ostree_pkg_mgr + block: + - name: Check if system is ostree + stat: + path: "{{ ostree_booted_file }}" + register: __ostree_booted_stat + + - name: Set package manager to use for ostree + ansible.utils.update_fact: + updates: + - path: ansible_facts.pkg_mgr + value: "{{ ostree_pkg_mgr }}" + when: __ostree_booted_stat.stat.exists + - name: Add Elasticsearch to metrics domain list set_fact: __metrics_domains: "{{ __metrics_domains + ['elasticsearch'] }}" diff --git a/tests/check_into_elasticsearch.yml b/tests/check_into_elasticsearch.yml index 217ef68..d2b9424 100644 --- a/tests/check_into_elasticsearch.yml +++ b/tests/check_into_elasticsearch.yml @@ -6,5 +6,6 @@ - name: Check the ansible_managed header in pcp2elasticsearch.service vars: - __test_config_path: /usr/lib/systemd/system/pcp2elasticsearch.service + __test_config_path: >- + {{ __elasticsearch_service_path }}/pcp2elasticsearch.service include_tasks: check_header.yml diff --git a/tests/tests_verify_from_elasticsearch.yml b/tests/tests_verify_from_elasticsearch.yml index fe0790e..9504664 100644 --- a/tests/tests_verify_from_elasticsearch.yml +++ b/tests/tests_verify_from_elasticsearch.yml @@ -3,11 +3,6 @@ - name: Test import from Elasticsearch hosts: all - roles: - - role: linux-system-roles.metrics - vars: - metrics_from_elasticsearch: true - pre_tasks: - name: Stop test meta: end_host @@ -19,6 +14,13 @@ import_tasks: get_services_state.yml tasks: + - name: Run the metrics role to configure Elasticsearch + include_role: + name: linux-system-roles.metrics + public: true + vars: + metrics_from_elasticsearch: true + - name: Check if import from Elasticsearch works include_tasks: check_from_elasticsearch.yml diff --git a/tests/tests_verify_mssql.yml b/tests/tests_verify_mssql.yml index 0e624c9..a08e5f8 100644 --- a/tests/tests_verify_mssql.yml +++ b/tests/tests_verify_mssql.yml @@ -19,6 +19,24 @@ - name: Save state of services import_tasks: get_services_state.yml + - name: Ensure correct package manager for ostree systems + vars: + ostree_pkg_mgr: ansible.posix.rhel_rpm_ostree + ostree_booted_file: /run/ostree-booted + when: ansible_facts.pkg_mgr | d("") != ostree_pkg_mgr + block: + - name: Check if system is ostree + stat: + path: "{{ ostree_booted_file }}" + register: __ostree_booted_stat + + - name: Set package manager to use for ostree + ansible.utils.update_fact: + updates: + - path: ansible_facts.pkg_mgr + value: "{{ ostree_pkg_mgr }}" + when: __ostree_booted_stat.stat.exists + - name: Ensure python3-pyodbc is installed package: name: python3-pyodbc diff --git a/tests/tests_verify_postfix.yml b/tests/tests_verify_postfix.yml index d10c829..79e38fd 100644 --- a/tests/tests_verify_postfix.yml +++ b/tests/tests_verify_postfix.yml @@ -18,6 +18,24 @@ - name: Save state of services import_tasks: get_services_state.yml + - name: Ensure correct package manager for ostree systems + vars: + ostree_pkg_mgr: ansible.posix.rhel_rpm_ostree + ostree_booted_file: /run/ostree-booted + when: ansible_facts.pkg_mgr | d("") != ostree_pkg_mgr + block: + - name: Check if system is ostree + stat: + path: "{{ ostree_booted_file }}" + register: __ostree_booted_stat + + - name: Set package manager to use for ostree + ansible.utils.update_fact: + updates: + - path: ansible_facts.pkg_mgr + value: "{{ ostree_pkg_mgr }}" + when: __ostree_booted_stat.stat.exists + - name: Ensure postfix is installed package: name: diff --git a/vars/main.yml b/vars/main.yml index 41becd9..0c73951 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -3,3 +3,15 @@ __metrics_domains: [] __metrics_accounts: {} + +__metrics_required_facts: + - distribution + - distribution_major_version + - distribution_version + - os_family + +# the subsets of ansible_facts that need to be gathered in case any of the +# facts in required_facts is missing; see the documentation of +# the 'gather_subset' parameter of the 'setup' module +__metrics_required_facts_subsets: "{{ ['!all', '!min'] + + __metrics_required_facts }}" diff --git a/vendor/github.com/performancecopilot/ansible-pcp/roles/elasticsearch/tasks/main.yml b/vendor/github.com/performancecopilot/ansible-pcp/roles/elasticsearch/tasks/main.yml index 2e08e83..71d6377 100644 --- a/vendor/github.com/performancecopilot/ansible-pcp/roles/elasticsearch/tasks/main.yml +++ b/vendor/github.com/performancecopilot/ansible-pcp/roles/elasticsearch/tasks/main.yml @@ -51,6 +51,20 @@ - elasticsearch_metrics_provider == 'pcp' - elasticsearch_agent | d(false) | bool +- name: Check if system is ostree + stat: + path: "{{ ostree_booted_file }}" + vars: + ostree_booted_file: /run/ostree-booted + register: __ostree_booted_stat + +- name: Ensure correct service path for ostree systems + when: + - __ostree_booted_stat.stat.exists + - __elasticsearch_service_path != "/etc/systemd/system" + set_fact: + __elasticsearch_service_path: /etc/systemd/system + - name: Ensure PCP Elasticsearch export service exists template: src: pcp2elasticsearch.service.j2