Skip to content

Commit b91af7f

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 <[email protected]>
1 parent 39382b4 commit b91af7f

22 files changed

+296
-1
lines changed

.ansible-lint

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@ exclude_paths:
2222
- examples/roles/
2323
mock_roles:
2424
- linux-system-roles.ssh
25+
mock_modules:
26+
- ansible.utils.update_fact

.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: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
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 roles_parent_dir
33+
ostree_dir="$1"
34+
role="$2"
35+
roles_parent_dir="$(dirname "$(dirname "$ostree_dir")")"
36+
rolesdir="$roles_parent_dir/$role/.ostree"
37+
# assumes collection format
38+
if [ -d "$rolesdir" ]; then
39+
echo "$rolesdir"
40+
return 0
41+
fi
42+
# assumes legacy role format like linux-system-roles.$role/
43+
for rolesdir in "$roles_parent_dir"/*-system-roles."$role"/.ostree; do
44+
if [ -d "$rolesdir" ]; then
45+
echo "$rolesdir"
46+
return 0
47+
fi
48+
done
49+
# look elsewhere
50+
if [ -n "${ANSIBLE_COLLECTIONS_PATHS:-}" ]; then
51+
for pth in ${ANSIBLE_COLLECTIONS_PATHS//:/ }; do
52+
rolesdir="$pth/ansible_collections/$role_collection_dir/roles/$role/.ostree"
53+
if [ -d "$rolesdir" ]; then
54+
echo "$rolesdir"
55+
return 0
56+
fi
57+
done
58+
fi
59+
return 1
60+
}
61+
62+
get_packages() {
63+
local ostree_dir pkgtype pkgfile rolefile
64+
ostree_dir="$1"
65+
for pkgtype in "${pkgtypes[@]}"; do
66+
for suff in "" "-$distro" "-${distro}-${major_ver}" "-${distro}-${ver}"; do
67+
pkgfile="$ostree_dir/packages-${pkgtype}${suff}.txt"
68+
if [ -f "$pkgfile" ]; then
69+
cat "$pkgfile"
70+
fi
71+
done
72+
rolefile="$ostree_dir/roles-${pkgtype}.txt"
73+
if [ -f "$rolefile" ]; then
74+
local roles role rolepath
75+
roles="$(cat "$rolefile")"
76+
for role in $roles; do
77+
rolepath="$(get_rolepath "$ostree_dir" "$role")"
78+
get_packages "$rolepath"
79+
done
80+
fi
81+
done | sort -u
82+
}
83+
84+
format_packages_json() {
85+
local comma pkgs pkg
86+
comma=""
87+
pkgs="["
88+
while read -r pkg; do
89+
pkgs="${pkgs}${comma}\"${pkg}\""
90+
comma=,
91+
done
92+
pkgs="${pkgs}]"
93+
echo "$pkgs"
94+
}
95+
96+
format_packages_raw() {
97+
cat
98+
}
99+
100+
format_packages_yaml() {
101+
while read -r pkg; do
102+
echo "- $pkg"
103+
done
104+
}
105+
106+
format_packages_toml() {
107+
while read -r pkg; do
108+
echo "[[packages]]"
109+
echo "name = \"$pkg\""
110+
echo "version = \"*\""
111+
done
112+
}
113+
114+
distro="${distro_ver%%-*}"
115+
ver="${distro_ver##*-}"
116+
if [[ "$ver" =~ ^([0-9]*) ]]; then
117+
major_ver="${BASH_REMATCH[1]}"
118+
else
119+
echo ERROR: cannot parse major version number from version "$ver"
120+
exit 1
121+
fi
122+
123+
"get_$category" "$ostree_dir" | "format_${category}_$format"

.ostree/packages-runtime.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
openssh
2+
openssh-clients
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
bash
2+
man-db
3+
openssh-ldap
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
bash
2+
man-db
3+
openssh-ldap
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
bash
2+
man-db
3+
openssh-keycat
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
bash
2+
man-db
3+
openssh-keycat
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
bash
2+
man-db
3+
openssh-ldap
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
bash
2+
man-db
3+
openssh-ldap

0 commit comments

Comments
 (0)