Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: improve support for ostree systems #134

Merged
merged 1 commit into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .ansible-lint
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,3 @@ exclude_paths:
- examples/roles/
mock_roles:
- linux-system-roles.cockpit
mock_modules:
- ansible.utils.update_fact
29 changes: 19 additions & 10 deletions .ostree/get_ostree_data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

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
Expand All @@ -29,7 +28,7 @@ if [ "$pkgtype" = testing ]; then
fi

get_rolepath() {
local ostree_dir role rolesdir roles_parent_dir
local ostree_dir role rolesdir roles_parent_dir coll_path pth
ostree_dir="$1"
role="$2"
roles_parent_dir="$(dirname "$(dirname "$ostree_dir")")"
Expand All @@ -47,16 +46,22 @@ get_rolepath() {
fi
done
# look elsewhere
if [ -n "${ANSIBLE_COLLECTIONS_PATHS:-}" ]; then
for pth in ${ANSIBLE_COLLECTIONS_PATHS//:/ }; do
rolesdir="$pth/ansible_collections/$role_collection_dir/roles/$role/.ostree"
if [ -d "$rolesdir" ]; then
echo "$rolesdir"
return 0
fi
coll_path="${ANSIBLE_COLLECTIONS_PATH:-}"
if [ -z "$coll_path" ]; then
coll_path="${ANSIBLE_COLLECTIONS_PATHS:-}"
fi
if [ -n "${coll_path}" ]; then
for pth in ${coll_path//:/ }; do
for rolesdir in "$pth"/ansible_collections/*/*_system_roles/roles/"$role"/.ostree; do
if [ -d "$rolesdir" ]; then
echo "$rolesdir"
return 0
fi
done
done
fi
return 1
1>&2 echo ERROR - could not find role "$role" - please use ANSIBLE_COLLECTIONS_PATH
exit 2
}

get_packages() {
Expand All @@ -75,6 +80,10 @@ get_packages() {
roles="$(cat "$rolefile")"
for role in $roles; do
rolepath="$(get_rolepath "$ostree_dir" "$role")"
if [ -z "$rolepath" ]; then
1>&2 echo ERROR - could not find role "$role" - please use ANSIBLE_COLLECTIONS_PATH
exit 2
fi
get_packages "$rolepath"
done
fi
Expand Down
1 change: 1 addition & 0 deletions .ostree/packages-runtime-CentOS-9.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cockpit-*
1 change: 0 additions & 1 deletion meta/collection-requirements.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@
---
collections:
- ansible.posix
- ansible.utils
- fedora.linux_system_roles
4 changes: 2 additions & 2 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
when:
- ansible_distribution == 'RedHat'
- ansible_distribution_major_version == '7'
- ansible_facts.pkg_mgr | d() != "ansible.posix.rhel_rpm_ostree"
- not __cockpit_is_ostree | d(false)
block:
- name: List active RHEL repositories
command:
Expand All @@ -27,7 +27,7 @@
with_first_found:
- "setup-{{ ansible_pkg_mgr }}.yml"
- "setup-default.yml"
when: ansible_facts.pkg_mgr | d() != "ansible.posix.rhel_rpm_ostree"
when: not __cockpit_is_ostree | d(false)

- name: Configure firewall
include_tasks: firewall.yml
Expand Down
18 changes: 6 additions & 12 deletions tasks/set_vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,17 @@
when: __cockpit_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
- name: Determine if system is ostree and set flag
when: not __cockpit_is_ostree is defined
block:
- name: Check if system is ostree
stat:
path: "{{ ostree_booted_file }}"
path: /run/ostree-booted
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 flag to indicate system is ostree
set_fact:
__cockpit_is_ostree: "{{ __ostree_booted_stat.stat.exists }}"

- name: Set version specific variables
include_vars: "{{ item }}"
Expand Down
2 changes: 1 addition & 1 deletion tests/tasks/cleanup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
- cockpit-ws
- cockpit-doc
state: absent
when: ansible_facts.pkg_mgr | d() != "ansible.posix.rhel_rpm_ostree"
when: not __cockpit_is_ostree | d(false)
tags:
- always
- tests::cleanup
Expand Down
24 changes: 12 additions & 12 deletions tests/tasks/install_selinux_tools.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
# SPDX-License-Identifier: MIT
---
- 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
- name: Determine if system is ostree and set flag
when: not __cockpit_is_ostree is defined
block:
- name: Check if system is ostree
stat:
path: "{{ ostree_booted_file }}"
path: /run/ostree-booted
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 flag to indicate system is ostree
set_fact:
__cockpit_is_ostree: "{{ __ostree_booted_stat.stat.exists }}"

- name: Install SELinux python2 tools
package:
name:
- libselinux-python
- policycoreutils-python
state: present
use: "{{ (__cockpit_is_ostree | d(false)) |
ternary('ansible.posix.rhel_rpm_ostree', omit) }}"
when:
- ansible_python_version is version('3', '<')
- ansible_distribution in ["Fedora", "CentOS", "RedHat", "Rocky"]
Expand All @@ -34,6 +30,8 @@
- python3-libselinux
- python3-policycoreutils
state: present
use: "{{ (__cockpit_is_ostree | d(false)) |
ternary('ansible.posix.rhel_rpm_ostree', omit) }}"
when:
- ansible_python_version is version('3', '>=')
- ansible_distribution in ["Fedora", "CentOS", "RedHat", "Rocky"]
Expand All @@ -43,6 +41,8 @@
name:
- policycoreutils-python-utils
state: present
use: "{{ (__cockpit_is_ostree | d(false)) |
ternary('ansible.posix.rhel_rpm_ostree', omit) }}"
when: ansible_distribution == "Fedora" or
(ansible_distribution_major_version | int > 7 and
ansible_distribution in ["CentOS", "RedHat", "Rocky"])
2 changes: 1 addition & 1 deletion tests/tests_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
msg: cockpit is unexpectedly installed
when:
- "'cockpit' in ansible_facts.packages"
- ansible_facts.pkg_mgr | d() != "ansible.posix.rhel_rpm_ostree"
- not __cockpit_is_ostree | d(false)

- name: Test - write expected configuration file
copy:
Expand Down
Loading