Skip to content

Commit 602fcc3

Browse files
committed
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 <rmeggins@redhat.com>
1 parent c4c0909 commit 602fcc3

20 files changed

+274
-0
lines changed

.ostree/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*NOTE*: The `*.txt` files are used by `get_ostree_data.sh` to create the lists
2+
of packages, and to find other system roles used by this role. DO NOT use them
3+
directly.

.ostree/get_ostree_data.sh

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
role_collection_dir="${ROLE_COLLECTION_DIR:-fedora/linux_system_roles}"
6+
ostree_dir="${OSTREE_DIR:-"$(dirname "$(realpath "$0")")"}"
7+
8+
if [ -z "${4:-}" ] || [ "${1:-}" = help ] || [ "${1:-}" = -h ]; then
9+
cat <<EOF
10+
Usage: $0 packages [runtime|testing] DISTRO-MAJOR[.MINOR] [json|yaml|raw|toml]
11+
The script will use the packages and roles files in $ostree_dir to
12+
construct the list of packages needed to build the ostree image. The script
13+
will output the list of packages in the given format
14+
- json is a JSON list like ["pkg1","pkg2",....,"pkgN"]
15+
- yaml is the YAML list format
16+
- raw is the list of packages, one per line
17+
- toml is a list of [[packages]] elements as in https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/9/html-single/composing_installing_and_managing_rhel_for_edge_images/index#creating-an-image-builder-blueprint-for-a-rhel-for-edge-image-using-the-command-line-interface_composing-a-rhel-for-edge-image-using-image-builder-command-line
18+
The DISTRO-MAJOR.MINOR is the same format used by Ansible for distribution e.g. CentOS-8, RedHat-8.9, etc.
19+
EOF
20+
exit 1
21+
fi
22+
category="$1"
23+
pkgtype="$2"
24+
distro_ver="$3"
25+
format="$4"
26+
pkgtypes=("$pkgtype")
27+
if [ "$pkgtype" = testing ]; then
28+
pkgtypes+=(runtime)
29+
fi
30+
31+
get_rolepath() {
32+
local ostree_dir role rolesdir
33+
ostree_dir="$1"
34+
role="$2"
35+
rolesdir="$(dirname "$(dirname "$ostree_dir")")/$role/.ostree"
36+
if [ -d "$rolesdir" ]; then
37+
echo "$rolesdir"
38+
return 0
39+
fi
40+
if [ -n "${ANSIBLE_COLLECTIONS_PATHS:-}" ]; then
41+
for pth in ${ANSIBLE_COLLECTIONS_PATHS//:/ }; do
42+
rolesdir="$pth/ansible_collections/$role_collection_dir/roles/$role/.ostree"
43+
if [ -d "$rolesdir" ]; then
44+
echo "$rolesdir"
45+
return 0
46+
fi
47+
done
48+
fi
49+
return 1
50+
}
51+
52+
get_packages() {
53+
local ostree_dir pkgtype pkgfile rolefile
54+
ostree_dir="$1"
55+
for pkgtype in "${pkgtypes[@]}"; do
56+
for suff in "" "-$distro" "-${distro}-${major_ver}" "-${distro}-${ver}"; do
57+
pkgfile="$ostree_dir/packages-${pkgtype}${suff}.txt"
58+
if [ -f "$pkgfile" ]; then
59+
cat "$pkgfile"
60+
fi
61+
done
62+
rolefile="$ostree_dir/roles-${pkgtype}.txt"
63+
if [ -f "$rolefile" ]; then
64+
local roles role rolepath
65+
roles="$(cat "$rolefile")"
66+
for role in $roles; do
67+
rolepath="$(get_rolepath "$ostree_dir" "$role")"
68+
get_packages "$rolepath"
69+
done
70+
fi
71+
done | sort -u
72+
}
73+
74+
format_packages_json() {
75+
local comma pkgs pkg
76+
comma=""
77+
pkgs="["
78+
while read -r pkg; do
79+
pkgs="${pkgs}${comma}\"${pkg}\""
80+
comma=,
81+
done
82+
pkgs="${pkgs}]"
83+
echo "$pkgs"
84+
}
85+
86+
format_packages_raw() {
87+
cat
88+
}
89+
90+
format_packages_yaml() {
91+
while read -r pkg; do
92+
echo "- $pkg"
93+
done
94+
}
95+
96+
format_packages_toml() {
97+
while read -r pkg; do
98+
echo "[[packages]]"
99+
echo "name = \"$pkg\""
100+
echo "version = \"*\""
101+
done
102+
}
103+
104+
distro="${distro_ver%%-*}"
105+
ver="${distro_ver##*-}"
106+
if [[ "$ver" =~ ^([0-9]*) ]]; then
107+
major_ver="${BASH_REMATCH[1]}"
108+
else
109+
echo ERROR: cannot parse major version number from version "$ver"
110+
exit 1
111+
fi
112+
113+
"get_$category" "$ostree_dir" | "format_${category}_$format"

.ostree/packages-runtime.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
firewalld
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
podman
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
podman
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
podman
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
podman
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
podman

.ostree/packages-testing.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
nftables

.sanity-ansible-ignore-2.12.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ plugins/modules/firewall_lib_facts.py validate-modules:missing-gplv3-license
33
plugins/modules/firewall_lib.py validate-modules:missing-examples
44
roles/firewall/files/get_files_checksums.sh shebang!skip
55
tests/firewall/files/test_ping.sh shebang!skip
6+
roles/firewall/.ostree/get_ostree_data.sh shebang!skip

0 commit comments

Comments
 (0)