From c0f6d69aad92aea5913beba0cea96ef74f910aef Mon Sep 17 00:00:00 2001 From: Rich Megginson Date: Tue, 31 Oct 2023 18:42:37 -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.txt | 1 + .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 | 12 ++- meta/collection-requirements.yml | 2 + tasks/main.yml | 28 +++++++ tasks/set_facts.yml | 18 +++++ 15 files changed, 261 insertions(+), 1 deletion(-) 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/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 792e377..0fdb58c 100644 --- a/.ansible-lint +++ b/.ansible-lint @@ -22,3 +22,5 @@ exclude_paths: - examples/roles/ mock_roles: - linux-system-roles.postfix +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 < Ensure to back up those files to preserve your settings. +**WARNING**: When managing `rpm-ostree` systems, the role cannot reinstall the +postfix package, so it just replaces the modified config files with empty files. +This is not idempotent. + If you specify only `previous: replaced` under the `postfix_conf` dictionary, the role re-installs the `postfix` package and enables the `postfix` service without applying any configuration. @@ -191,6 +197,10 @@ set to true `postfix_backup` is ignored): - linux-system-roles.postfix ``` +## rpm-ostree + +See README-ostree.md + ## License Copyright (C) 2017 Jaroslav Škarvada diff --git a/meta/collection-requirements.yml b/meta/collection-requirements.yml index d2b6e5b..e22fbe0 100644 --- a/meta/collection-requirements.yml +++ b/meta/collection-requirements.yml @@ -1,4 +1,6 @@ # SPDX-License-Identifier: MIT --- collections: + - ansible.posix + - ansible.utils - fedora.linux_system_roles diff --git a/tasks/main.yml b/tasks/main.yml index ea9402d..4f74a69 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -8,6 +8,7 @@ when: - postfix_conf.previous is defined - postfix_conf.previous == "replaced" + - ansible_facts.pkg_mgr | d() != "ansible.posix.rhel_rpm_ostree" block: # It is assumed that the only package providing config files that might # be modified is postfix - if this is not so, then additional @@ -29,6 +30,33 @@ selectattr('stdout', 'search', ' /etc/postfix/.*[.]cf($|\n)') | list | length > 0 +- name: Remove configuration for replacement + when: + - postfix_conf.previous | d() == "replaced" + - ansible_facts.pkg_mgr | d() == "ansible.posix.rhel_rpm_ostree" + block: + # It is assumed that the only package providing config files that might + # be modified is postfix - if this is not so, then additional + # packages need to be added to this check + - name: Get status of config files + command: rpm -V --nomtime {{ item }} # noqa command-instead-of-module + loop: "{{ __postfix_packages }}" + register: __postfix_packages_status + failed_when: false + changed_when: false + + - name: Remove config files - make empty + copy: + dest: "{{ item }}" + content: "\n" # to make postconf -e happy + mode: preserve + loop: "{{ mod_cf_files }}" + vars: + mod_cf_files: "{{ __postfix_packages_status.results | + map(attribute='stdout') | map('default', '') | + map('regex_findall', ' (/etc/postfix/.*[.]cf)(?:$|\n)') | select | + flatten | list }}" + - name: Configure firewall include_tasks: firewall.yml diff --git a/tasks/set_facts.yml b/tasks/set_facts.yml index 05f46af..3bac5b6 100644 --- a/tasks/set_facts.yml +++ b/tasks/set_facts.yml @@ -5,3 +5,21 @@ gather_subset: "{{ __postfix_required_facts_subsets }}" when: __postfix_required_facts | difference(ansible_facts.keys() | list) | length > 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