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

feat: support for ostree systems #399

Merged
merged 1 commit into from
Oct 30, 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
3 changes: 3 additions & 0 deletions .ostree/README.md
Original file line number Diff line number Diff line change
@@ -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.
123 changes: 123 additions & 0 deletions .ostree/get_ostree_data.sh
Original file line number Diff line number Diff line change
@@ -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 <<EOF
Usage: $0 packages [runtime|testing] DISTRO-MAJOR[.MINOR] [json|yaml|raw|toml]
The script will use the packages and roles files in $ostree_dir to
construct the list of packages needed to build the ostree image. The script
will output the list of packages in the given format
- json is a JSON list like ["pkg1","pkg2",....,"pkgN"]
- yaml is the YAML list format
- raw is the list of packages, one per line
- 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
The DISTRO-MAJOR.MINOR is the same format used by Ansible for distribution e.g. CentOS-8, RedHat-8.9, etc.
EOF
exit 1
fi
category="$1"
pkgtype="$2"
distro_ver="$3"
format="$4"
pkgtypes=("$pkgtype")
if [ "$pkgtype" = testing ]; then
pkgtypes+=(runtime)
fi

get_rolepath() {
local ostree_dir role rolesdir roles_parent_dir
ostree_dir="$1"
role="$2"
roles_parent_dir="$(dirname "$(dirname "$ostree_dir")")"
rolesdir="$roles_parent_dir/$role/.ostree"
# assumes collection format
if [ -d "$rolesdir" ]; then
echo "$rolesdir"
return 0
fi
# assumes legacy role format like linux-system-roles.$role/
for rolesdir in "$roles_parent_dir"/*-system-roles."$role"/.ostree; do
if [ -d "$rolesdir" ]; then
echo "$rolesdir"
return 0
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
done
fi
return 1
}

get_packages() {
local ostree_dir pkgtype pkgfile rolefile
ostree_dir="$1"
for pkgtype in "${pkgtypes[@]}"; do
for suff in "" "-$distro" "-${distro}-${major_ver}" "-${distro}-${ver}"; do
pkgfile="$ostree_dir/packages-${pkgtype}${suff}.txt"
if [ -f "$pkgfile" ]; then
cat "$pkgfile"
fi
done
rolefile="$ostree_dir/roles-${pkgtype}.txt"
if [ -f "$rolefile" ]; then
local roles role rolepath
roles="$(cat "$rolefile")"
for role in $roles; do
rolepath="$(get_rolepath "$ostree_dir" "$role")"
get_packages "$rolepath"
done
fi
done | sort -u
}

format_packages_json() {
local comma pkgs pkg
comma=""
pkgs="["
while read -r pkg; do
pkgs="${pkgs}${comma}\"${pkg}\""
comma=,
done
pkgs="${pkgs}]"
echo "$pkgs"
}

format_packages_raw() {
cat
}

format_packages_yaml() {
while read -r pkg; do
echo "- $pkg"
done
}

format_packages_toml() {
while read -r pkg; do
echo "[[packages]]"
echo "name = \"$pkg\""
echo "version = \"*\""
done
}

distro="${distro_ver%%-*}"
ver="${distro_ver##*-}"
if [[ "$ver" =~ ^([0-9]*) ]]; then
major_ver="${BASH_REMATCH[1]}"
else
echo ERROR: cannot parse major version number from version "$ver"
exit 1
fi

"get_$category" "$ostree_dir" | "format_${category}_$format"
2 changes: 2 additions & 0 deletions .ostree/packages-runtime-CentOS-7.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
python-blivet3
python-enum34
3 changes: 3 additions & 0 deletions .ostree/packages-runtime-CentOS-8.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kmod-kvdo
python3-blivet
vdo
3 changes: 3 additions & 0 deletions .ostree/packages-runtime-CentOS-9.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kmod-kvdo
python3-blivet
vdo
1 change: 1 addition & 0 deletions .ostree/packages-runtime-Fedora.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python3-blivet
2 changes: 2 additions & 0 deletions .ostree/packages-runtime-RedHat-7.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
python-blivet3
python-enum34
3 changes: 3 additions & 0 deletions .ostree/packages-runtime-RedHat-8.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kmod-kvdo
python3-blivet
vdo
3 changes: 3 additions & 0 deletions .ostree/packages-runtime-RedHat-9.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kmod-kvdo
python3-blivet
vdo
10 changes: 10 additions & 0 deletions .ostree/packages-runtime.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
cryptsetup
e2fsprogs
kpartx
libblockdev-crypto
libblockdev-dm
libblockdev-lvm
libblockdev-mdraid
libblockdev-swap
lvm2
xfsprogs
2 changes: 2 additions & 0 deletions .ostree/packages-testing-CentOS-7.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dracut-fips
util-linux
1 change: 1 addition & 0 deletions .ostree/packages-testing-CentOS-8.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
util-linux
1 change: 1 addition & 0 deletions .ostree/packages-testing-CentOS-9.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
util-linux-core
2 changes: 2 additions & 0 deletions .ostree/packages-testing-Fedora.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
nilfs-utils
util-linux-core
2 changes: 2 additions & 0 deletions .ostree/packages-testing-RedHat-7.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dracut-fips
util-linux
1 change: 1 addition & 0 deletions .ostree/packages-testing-RedHat-8.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
util-linux
1 change: 1 addition & 0 deletions .ostree/packages-testing-RedHat-9.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
util-linux-core
2 changes: 2 additions & 0 deletions .ostree/packages-testing.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bc
cryptsetup
1 change: 1 addition & 0 deletions .sanity-ansible-ignore-2.10.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ tests/storage/scripts/generate_tests.py future-import-boilerplate!skip
tests/storage/scripts/generate_tests.py shebang!skip
tests/storage/scripts/post-commit shebang!skip
tests/storage/scripts/pre-commit shebang!skip
roles/storage/.ostree/get_ostree_data.sh shebang!skip
1 change: 1 addition & 0 deletions .sanity-ansible-ignore-2.11.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ tests/storage/scripts/generate_tests.py future-import-boilerplate!skip
tests/storage/scripts/generate_tests.py shebang!skip
tests/storage/scripts/post-commit shebang!skip
tests/storage/scripts/pre-commit shebang!skip
roles/storage/.ostree/get_ostree_data.sh shebang!skip
1 change: 1 addition & 0 deletions .sanity-ansible-ignore-2.12.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ plugins/module_utils/storage_lsr/size.py pylint!skip
tests/storage/scripts/generate_tests.py shebang!skip
tests/storage/scripts/post-commit shebang!skip
tests/storage/scripts/pre-commit shebang!skip
roles/storage/.ostree/get_ostree_data.sh shebang!skip
1 change: 1 addition & 0 deletions .sanity-ansible-ignore-2.13.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ plugins/module_utils/storage_lsr/size.py pylint!skip
tests/storage/scripts/generate_tests.py shebang!skip
tests/storage/scripts/post-commit shebang!skip
tests/storage/scripts/pre-commit shebang!skip
roles/storage/.ostree/get_ostree_data.sh shebang!skip
1 change: 1 addition & 0 deletions .sanity-ansible-ignore-2.14.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ plugins/module_utils/storage_lsr/size.py pylint!skip
tests/storage/scripts/generate_tests.py shebang!skip
tests/storage/scripts/post-commit shebang!skip
tests/storage/scripts/pre-commit shebang!skip
roles/storage/.ostree/get_ostree_data.sh shebang!skip
1 change: 1 addition & 0 deletions .sanity-ansible-ignore-2.15.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ plugins/module_utils/storage_lsr/size.py pylint!skip
tests/storage/scripts/generate_tests.py shebang!skip
tests/storage/scripts/post-commit shebang!skip
tests/storage/scripts/pre-commit shebang!skip
roles/storage/.ostree/get_ostree_data.sh shebang!skip
1 change: 1 addition & 0 deletions .sanity-ansible-ignore-2.9.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ tests/storage/scripts/generate_tests.py future-import-boilerplate!skip
tests/storage/scripts/generate_tests.py shebang!skip
tests/storage/scripts/post-commit shebang!skip
tests/storage/scripts/pre-commit shebang!skip
roles/storage/.ostree/get_ostree_data.sh shebang!skip
66 changes: 66 additions & 0 deletions README-ostree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# rpm-ostree

The role supports running on [rpm-ostree](https://coreos.github.io/rpm-ostree/)
systems. The primary issue is that the `/usr` filesystem is read-only, and the
role cannot install packages. Instead, it will just verify that the necessary
packages and any other `/usr` files are pre-installed. The role will change the
package manager to one that is compatible with `rpm-ostree` systems.

## Building

To build an ostree image for a particular operating system distribution and
version, use the script `.ostree/get_ostree_data.sh` to get the list of
packages. If the role uses other system roles, then the script will include the
packages for the other roles in the list it outputs. The list of packages will
be sorted in alphanumeric order.

Usage:

```bash
.ostree/get_ostree_data.sh packages runtime DISTRO-VERSION FORMAT
```

`DISTRO-VERSION` is in the format that Ansible uses for `ansible_distribution`
and `ansible_distribution_version` - for example, `Fedora-38`, `CentOS-8`,
`RedHat-9.4`

`FORMAT` is one of `toml`, `json`, `yaml`, `raw`

* `toml` - each package in a TOML `[[packages]]` element

```toml
[[packages]]
name = "package-a"
version = "*"
[[packages]]
name = "package-b"
version = "*"
...
```

* `yaml` - a YAML list of packages

```yaml
- package-a
- package-b
...
```

* `json` - a JSON list of packages

```json
["package-a","package-b",...]
```

* `raw` - a plain text list of packages, one per line

```bash
package-a
package-b
...
```

What format you choose depends on which image builder you are using. For
example, if you are using something based on
[osbuild-composer](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),
you will probably want to use the `toml` output format.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,13 @@ See below

### Collection requirements

The role requires the `mount` module from `ansible.posix`. If you are using
`ansible-core`, you must install the `ansible.posix` collection.
The role requires external collections. Use the following command to install
them:

```bash
ansible-galaxy collection install -vv -r meta/collection-requirements.yml
```

If you are using Ansible Engine 2.9, or are using an Ansible bundle which
includes these collections/modules, you should have to do nothing.

## Role Variables

__NOTE__: Beginning with version 1.3.0, unspecified parameters are interpreted
Expand Down Expand Up @@ -358,6 +355,10 @@ platforms with "buggy" udev.

```

## rpm-ostree

See README-ostree.md

## License

MIT
1 change: 1 addition & 0 deletions meta/collection-requirements.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
collections:
- name: ansible.posix
- name: ansible.utils
9 changes: 8 additions & 1 deletion tasks/main-blivet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,17 @@

- name: Make sure required packages are installed
package:
name: "{{ package_info.packages }}"
name: "{{ package_info.packages + extra_pkgs }}"
state: present
when: storage_skip_checks is not defined or
not "packages_installed" in storage_skip_checks
vars:
# for some reason the blivet module does not pick up on the
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vojtechtrefny @japokorn I don't know why blivet does not add kpartx to the list of packages in this case. Without this, ostree image building does not know to add the kpartx package to the image, and some of the tests fail such as tests_change_fs and tests_change_mount, because the kpartx command is not available. Looks like devices/dm.py in blivet lists kpartx as a dependency, but not as a package, and the storage blivet module uses the package lists from the devices.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think kpartx is not listed in packages for DMDevice because all other Device Mapper devices (like all LVM and LUKS device classes) are based on it and we don't need kpartx for those -- only for MultiPath and linear DM devices with partitions. Do you have logs for the failed tests? I think the test suite should never run into a situation where the setup_partitions function is actually called so kpartx shouldn't be needed.

But we should definitely do a better work in blivet and be able to still work without kpartx without crashing/raising exception.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is the error from running tests_change_mount.yml against an ostree image which has all of the packages reported by blivet:

Traceback (most recent call last):\r\n  File "/root/.ansible/tmp/ansible-tmp-1698677588.077884-2411506-87522188525601/AnsiballZ_blivet.py", line 107, in <module>
 _ansiballz_main()
  File "/root/.ansible/tmp/ansible-tmp-1698677588.077884-2411506-87522188525601/AnsiballZ_blivet.py", line 99, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File "/root/.ansible/tmp/ansible-tmp-1698677588.077884-2411506-87522188525601/AnsiballZ_blivet.py", line 48, in invoke_module
    run_name=\'__main__\', alter_sys=True)
  File "/usr/lib64/python3.6/runpy.py", line 205, in run_module
    return _run_module_code(code, init_globals, run_name, mod_spec)
  File "/usr/lib64/python3.6/runpy.py", line 96, in _run_module_code
    mod_name, mod_spec, pkg_name, script_name)
  File "/usr/lib64/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)\r\n  File "/tmp/ansible_blivet_payload_nf2a9eb0/ansible_blivet_payload.zip/ansible/modules/blivet.py", line 1983, in <module>
  File "/tmp/ansible_blivet_payload_nf2a9eb0/ansible_blivet_payload.zip/ansible/modules/blivet.py", line 1979, in main
  File "/tmp/ansible_blivet_payload_nf2a9eb0/ansible_blivet_payload.zip/ansible/modules/blivet.py", line 1931, in run_module
  File "/tmp/ansible_blivet_payload_nf2a9eb0/ansible_blivet_payload.zip/ansible/modules/blivet.py", line 1575, in manage_pool
  File "/tmp/ansible_blivet_payload_nf2a9eb0/ansible_blivet_payload.zip/ansible/modules/blivet.py", line 1323, in manage
  File "/tmp/ansible_blivet_payload_nf2a9eb0/ansible_blivet_payload.zip/ansible/modules/blivet.py", line 1294, in _manage_volumes
  File "/tmp/ansible_blivet_payload_nf2a9eb0/ansible_blivet_payload.zip/ansible/modules/blivet.py", line 594, in manage
  File "/tmp/ansible_blivet_payload_nf2a9eb0/ansible_blivet_payload.zip/ansible/modules/blivet.py", line 933, in _create
  File "/usr/lib/python3.6/site-packages/blivet/threads.py", line 53, in run_with_lock
    return m(*args, **kwargs)
  File "/usr/lib/python3.6/site-packages/blivet/blivet.py", line 872, in create_device
    action_create_dev = ActionCreateDevice(device)
  File "/usr/lib/python3.6/site-packages/blivet/threads.py", line 53, in run_with_lock
    return m(*args, **kwargs)
  File "/usr/lib/python3.6/site-packages/blivet/deviceaction.py", line 331, in __init__
    DeviceAction.__init__(self, device)
  File "/usr/lib/python3.6/site-packages/blivet/threads.py", line 53, in run_with_lock
    return m(*args, **kwargs)
  File "/usr/lib/python3.6/site-packages/blivet/deviceaction.py", line 168, in __init__
    self._check_device_dependencies()
  File "/usr/lib/python3.6/site-packages/blivet/threads.py", line 53, in run_with_lock
    return m(*args, **kwargs)
  File "/usr/lib/python3.6/site-packages/blivet/deviceaction.py", line 177, in _check_device_dependencies
    raise DependencyError("device type %s requires unavailable_dependencies: %s" % (self.device.type, dependencies_str))
blivet.errors.DependencyError: device type lvmlv requires unavailable_dependencies: kpartx:
application kpartx is not in $PATH

I don't know what is pulling in the kpartx dependency, but it is there.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I forgot the dependencies are also inherited so all LVM devices depend on kpartx. As I said we'll fix this in blivet (storaged-project/blivet#1165), but for now let's keep the kpartx dependency in the extra packages here as well.

# kpartx dependency, and I'm not sure from the role parameters
# how to know if kpartx is needed - so maybe this can be moved
# into blivet, or made conditional
extra_pkgs:
- kpartx

- name: Get service facts
service_facts:
Expand Down
18 changes: 18 additions & 0 deletions tasks/set_vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,21 @@
vars:
__vars_file: "{{ role_path }}/vars/{{ item }}"
when: __vars_file is file

- 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
12 changes: 12 additions & 0 deletions tests/get_unused_disk.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
---
- name: Ensure test packages
package:
name: "{{ test_packages }}"
state: present
vars:
# util-linux needed for lsblk, findmnt, etc.
test_packages: "{{ ['util-linux-core']
if (ansible_facts['os_family'] == 'RedHat' and
ansible_facts['distribution_major_version'] is version('8', '>'))
else ['util-linux'] if ansible_facts['os_family'] == 'RedHat'
else ['util-linux'] }}"

- name: Find unused disks in the system
find_unused_disk:
min_size: "{{ min_size | d(omit) }}"
Expand Down
Loading
Loading