Files
Kamino/scripts/run_molecule_in_ci_image.sh
T
Dragonish 26b6e37a09
Build / build (pull_request) Successful in 34s
Lint / lint (pull_request) Successful in 2m32s
Molecule / molecule (pull_request) Canceled after 6m34s
fix: read facts through ansible_facts and run Molecule with fact injection off
ansible-core deprecates injecting facts as top-level variables (removal is
scheduled for 2.24, see #364). Three roles still read a bare fact: system_baseline (reboot check,
ansible_os_family), docker (APT source line, ansible_distribution_release)
and gitea_runner (re-registration backup name, ansible_date_time). With
inject_facts_as_vars set to false the system_baseline reboot check failed
with "'ansible_os_family' is undefined".

They now read ansible_facts[...]; the argument specs and READMEs that name
the facts follow. run_molecule_in_ci_image.sh exports
ANSIBLE_INJECT_FACT_VARS=False, so a role that reads an injected fact fails
its scenario, and a script test keeps the export in place.

Refs #364

Assisted-by: Claude Code:claude-sonnet-5-5
2026-11-26 21:33:03 +00:00

40 lines
2.0 KiB
Bash
Executable File

#!/usr/bin/env bash
# SPDX-FileCopyrightText: Defame1297 and contributors
# SPDX-License-Identifier: GPL-3.0-or-later
#
# The Molecule workflow's run inside the ci image, from the checkout root: when a pin file differs
# from the image's, install the pull request's pins into $AC_ROOT/pins (/opt is not writable for the
# runner user) and put them first, then check that the scenarios on stdin load this checkout and run
# them. CI_BASE_PYTHON is a test seam.
#
# AC_ROOT=<dir holding ansible_collections> scripts/run_molecule_in_ci_image.sh < scenario-dirs
set -euo pipefail
selected="$(cat)"
pins="$AC_ROOT/pins"
extra_collections=""
if sha256sum --quiet -c /opt/ci-pins.sha256; then
echo "The pin files match the ci image; using the baked tools."
else
echo "::warning::a pin file differs from the ci image; installing the pinned tools and collections for this run."
"${CI_BASE_PYTHON:-/opt/venv/bin/python}" -m venv "$pins/venv"
"$pins/venv/bin/pip" install --quiet --require-hashes -r requirements-dev.lock -r requirements-dev.txt
export PATH="$pins/venv/bin:$PATH"
# The target alone on the path, so a baked copy is not taken as already installed.
for req in requirements.yml extensions/molecule/requirements.yml; do
ANSIBLE_COLLECTIONS_PATH="$pins/collections" \
ansible-galaxy collection install --force -r "$req" -p "$pins/collections"
done
extra_collections="$pins/collections:"
fi
ansible --version
molecule --version
# The collection under test first; molecule also installs it into each scenario's ANSIBLE_HOME,
# which the run script keeps in the job tree.
export ANSIBLE_COLLECTIONS_PATH="$AC_ROOT:${extra_collections}/opt/collections"
# Facts are not injected as variables (deprecated in ansible-core 2.22, removal scheduled for 2.24, see #364), so a
# role that reads a bare `ansible_<fact>` fails its scenario here instead of in a consumer's inventory.
export ANSIBLE_INJECT_FACT_VARS=False
python3 -I scripts/check_scenarios_load_checkout.py <<< "$selected"
exec scripts/run_molecule_scenarios.sh "$AC_ROOT/molecule-runs" <<< "$selected"