From eb892c6f3bdad010d26ee0f2364b76554ad36336 Mon Sep 17 00:00:00 2001 From: Rich Megginson Date: Wed, 15 Nov 2023 14:28:43 -0700 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 | 1 + .ostree/README.md | 3 + .ostree/get_ostree_data.sh | 123 +++++++++++++++++++++++++++++++ .ostree/packages-runtime.txt | 4 + .ostree/packages-testing.txt | 1 + .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 | 12 +-- meta/collection-requirements.yml | 2 + tasks/set_vars.yml | 18 +++++ tests/tasks/setup.yml | 25 +++++++ tests/tests_cockpit.yml | 5 ++ tests/tests_default.yml | 4 +- tests/tests_default_vars.yml | 3 + tests/tests_example.yml | 3 + tests/tests_sssd.yml | 3 + 20 files changed, 272 insertions(+), 6 deletions(-) create mode 100644 .ostree/README.md create mode 100755 .ostree/get_ostree_data.sh create mode 100644 .ostree/packages-runtime.txt create mode 100644 .ostree/packages-testing.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 create mode 100644 tests/tasks/setup.yml diff --git a/.ansible-lint b/.ansible-lint index 1474aad..34c98ee 100644 --- a/.ansible-lint +++ b/.ansible-lint @@ -22,5 +22,6 @@ exclude_paths: - examples/roles/ mock_modules: - ini_file + - ansible.utils.update_fact mock_roles: - linux-system-roles.tlog 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: Set platform/version specific variables include_vars: "{{ __vars_file }}" loop: diff --git a/tests/tasks/setup.yml b/tests/tasks/setup.yml new file mode 100644 index 0000000..bd87e96 --- /dev/null +++ b/tests/tasks/setup.yml @@ -0,0 +1,25 @@ +--- +# common test setup tasks +- name: Check if system is ostree + stat: + path: "{{ ostree_booted_file }}" + register: __ostree_booted_stat + vars: + ostree_booted_file: /run/ostree-booted + +- name: Skip test if not supported on ostree + meta: end_host + when: + - __ostree_booted_stat.stat.exists + - __tlog_unsupported_ostree | d(false) + +- name: Ensure sssd user/group exist in /etc files + shell: | + if ! grep -q ^sssd /etc/passwd && grep -q ^sssd /usr/lib/passwd; then + grep ^sssd /usr/lib/passwd >> /etc/passwd + fi + if ! grep -q ^sssd /etc/group && grep -q ^sssd /usr/lib/group; then + grep ^sssd /usr/lib/group >> /etc/group + fi + when: __ostree_booted_stat.stat.exists + changed_when: true diff --git a/tests/tests_cockpit.yml b/tests/tests_cockpit.yml index 0a229b7..1a6d0cf 100644 --- a/tests/tests_cockpit.yml +++ b/tests/tests_cockpit.yml @@ -2,6 +2,11 @@ - name: Test support for autoinstall of cockpit-session-recording hosts: all tasks: + - name: Test setup and check for ostree + include_tasks: tasks/setup.yml + vars: + __tlog_unsupported_ostree: true + - name: Get the rpm package facts package_facts: diff --git a/tests/tests_default.yml b/tests/tests_default.yml index 4665b5e..37fd6f3 100644 --- a/tests/tests_default.yml +++ b/tests/tests_default.yml @@ -1,7 +1,9 @@ --- - name: Ensure that the role runs with default parameters hosts: all - roles: - linux-system-roles.tlog gather_facts: false + pre_tasks: + - name: Test setup and check for ostree + include_tasks: tasks/setup.yml diff --git a/tests/tests_default_vars.yml b/tests/tests_default_vars.yml index 93f5075..4c73c30 100644 --- a/tests/tests_default_vars.yml +++ b/tests/tests_default_vars.yml @@ -3,6 +3,9 @@ hosts: all roles: - linux-system-roles.tlog + pre_tasks: + - name: Test setup and check for ostree + include_tasks: tasks/setup.yml tasks: - name: Check that all variables are defined assert: diff --git a/tests/tests_example.yml b/tests/tests_example.yml index 391fc06..f60b308 100644 --- a/tests/tests_example.yml +++ b/tests/tests_example.yml @@ -7,3 +7,6 @@ tlog_scope_sssd: some tlog_users_sssd: - recordeduser + pre_tasks: + - name: Test setup and check for ostree + include_tasks: tasks/setup.yml diff --git a/tests/tests_sssd.yml b/tests/tests_sssd.yml index 5c2b20a..6b0c785 100644 --- a/tests/tests_sssd.yml +++ b/tests/tests_sssd.yml @@ -3,6 +3,9 @@ hosts: all tasks: + - name: Test setup and check for ostree + include_tasks: tasks/setup.yml + - name: Run role with default sssd settings import_role: name: linux-system-roles.tlog