Ansible galaxy imports seem to be broken after system update

Problem: After doing a standard system update and performing Foreman’s update process after reboot, Ansible no longer wants to import galaxy collections and fails with ERROR! Unexpected Exception, this is probably a bug: error parsing collection metadata: expected a single document in the stream

First discovered after I found out that ansible-core no longer ships with some collections I use, seems to also affect local collections I import from our internal git.

Expected outcome: Ansible galaxy collections are imported without issue.

Foreman and Proxy versions: 3.18.2, Katello 4.20.1

Foreman and Proxy plugin versions: 3.18.2

Distribution and version: Rocky 9.8

Other relevant data:

# ansible-galaxy collection install ansible.posix:2.2.1 -vvv
ansible-galaxy [core 2.16.14]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.12/site-packages/ansible
  ansible collection location = /etc/ansible/.ansible/collections:/root/.ansible/collections:/usr/share/ansible/collections:/etc/ansible/collections
  executable location = /bin/ansible-galaxy
  python version = 3.12.13 (main, Jul 10 2026, 00:00:00) [GCC 11.5.0 20240719 (Red Hat 11.5.0-14)] (/usr/bin/python3.12)
  jinja version = 3.1.6
  libyaml = False
Using /etc/ansible/ansible.cfg as config file
[DEPRECATION WARNING]: [defaults]collections_paths option, does not fit var naming standard, use the singular form collections_path instead. This feature will be
removed from ansible-core in version 2.19. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.
Starting galaxy collection install process
ERROR! Unexpected Exception, this is probably a bug: error parsing collection metadata: expected a single document in the stream
but found another document
  in "<byte string>", line 53, column 1:
    ---
    ^
the full traceback was:

Traceback (most recent call last):
  File "/usr/lib/python3.12/site-packages/ansible/utils/collection_loader/_collection_finder.py", line 781, in _load_module
    routing_dict = _meta_yml_to_dict(raw_routing, (collection_name, 'runtime.yml'))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/ansible/utils/collection_loader/_collection_meta.py", line 27, in _meta_yml_to_dict
    routing_dict = yaml_load(yaml_string_data)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.12/site-packages/yaml/__init__.py", line 81, in load
    return loader.get_single_data()
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.12/site-packages/yaml/constructor.py", line 49, in get_single_data
    node = self.get_single_node()
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.12/site-packages/yaml/composer.py", line 41, in get_single_node
    raise ComposerError("expected a single document in the stream",
yaml.composer.ComposerError: expected a single document in the stream
but found another document
  in "<byte string>", line 53, column 1:
    ---
    ^

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.12/site-packages/ansible/cli/__init__.py", line 659, in cli_executor
    exit_code = cli.run()
                ^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/ansible/cli/galaxy.py", line 772, in run
    return context.CLIARGS['func']()
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/ansible/cli/galaxy.py", line 120, in method_wrapper
    return wrapped_method(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/ansible/cli/galaxy.py", line 1432, in execute_install
    self._execute_install_collection(
  File "/usr/lib/python3.12/site-packages/ansible/cli/galaxy.py", line 1481, in _execute_install_collection
    install_collections(
  File "/usr/lib/python3.12/site-packages/ansible/galaxy/collection/__init__.py", line 670, in install_collections
    existing_collections = {
                           ^
  File "/usr/lib/python3.12/site-packages/ansible/galaxy/collection/__init__.py", line 1457, in find_existing_collections
    collection_path = files(f'ansible_collections.{namespace}.{name}')
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.12/importlib/resources/_common.py", line 46, in wrapper
    return func(anchor)
           ^^^^^^^^^^^^
  File "/usr/lib64/python3.12/importlib/resources/_common.py", line 56, in files
    return from_package(resolve(anchor))
                        ^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.12/functools.py", line 912, in wrapper
    return dispatch(args[0].__class__)(*args, **kw)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.12/importlib/resources/_common.py", line 82, in _
    return importlib.import_module(cand)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.12/importlib/__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "/usr/lib/python3.12/site-packages/ansible/utils/collection_loader/_collection_finder.py", line 792, in exec_module
    self._load_module(module)
  File "/usr/lib/python3.12/site-packages/ansible/utils/collection_loader/_collection_finder.py", line 784, in _load_module
    raise ValueError('error parsing collection metadata: {0}'.format(to_native(ex)))
ValueError: error parsing collection metadata: expected a single document in the stream
but found another document
  in "<byte string>", line 53, column 1:
    ---
    ^

Something seems to be broken with the foreman packaging of ansible-core and its link to Python 3.12 - uninstalling the ansible-core package from the foreman-plugins repository and installing the one from the distribution’s AppStream repo (Ansible 2.14) gets things working again.