CI/molecule: use common vars as well and simplify run (#13520)

The molecule_run.sh isn't really needed since the switch to gitlab-ci
matrix runs.

Also use the inventory variables pattern for kata-containers.
This commit is contained in:
Max Gautier
2026-09-17 09:09:23 +00:00
committed by GitHub
parent bd20622a16
commit 66f8da3f04
9 changed files with 40 additions and 45 deletions
+3 -7
View File
@@ -1,5 +1,5 @@
---
.molecule:
molecule:
tags: [ffci]
rules: # run on ci-short as well
- if: $CI_COMMIT_BRANCH =~ /^pr-.*$/
@@ -13,7 +13,8 @@
needs:
- pipeline-image
script:
- ./tests/scripts/molecule_run.sh
- cd roles/$ROLE
- molecule test --all -- --extra-vars @${CI_PROJECT_DIR}/tests/common_vars.yml
after_script:
- rm -fr molecule_logs
- mkdir -p molecule_logs
@@ -23,11 +24,6 @@
when: always
paths:
- molecule_logs/
molecule:
extends: .molecule
script:
- ./tests/scripts/molecule_run.sh -i $ROLE
parallel:
matrix:
- ROLE:
+1 -1
View File
@@ -25,7 +25,7 @@ pre-commit run -a # To run pre-commit hook on all files in the repository, even
#### Molecule
[molecule](https://github.com/ansible-community/molecule) is designed to help the development and testing of Ansible roles. In Kubespray you can run it all for all roles with `./tests/scripts/molecule_run.sh` or for a specific role (that you are working with) with `molecule test` from the role directory (`cd roles/my-role`).
[molecule](https://github.com/ansible-community/molecule) is designed to help the development and testing of Ansible roles. In Kubespray you can run it all for all roles with `find roles -name molecule -type d -execdir molecule test --all -- -e @$PWD/tests/common_vars.yml \;` or for a specific role (that you are working with) with `molecule test` from the role directory (`cd roles/my-role`).
When developing or debugging a role it can be useful to run `molecule create` and `molecule converge` separately. Then you can use `molecule login` to SSH into the test environment.
@@ -6,6 +6,12 @@
- name: Get kubespray defaults
import_role:
name: ../../../../../kubespray_defaults
- name: Get OS facts (needed for bin_dir resolution)
setup:
gather_subset:
- '!all'
- '!min'
- 'distribution'
- name: Test version
command: "{{ bin_dir }}/runsc --version"
register: runsc_version
@@ -2,9 +2,6 @@
- name: Converge
hosts: all
become: true
vars:
kata_containers_enabled: true
container_manager: containerd
roles:
- role: kubespray_defaults
- role: container-engine/containerd
@@ -7,12 +7,16 @@ platforms:
vm_memory: 1024
node_groups:
- kube_control_plane
- kube_node
- k8s_cluster
- name: ubuntu24
cloud_image: ubuntu-2404
vm_cpu_cores: 1
vm_memory: 1024
node_groups:
- kube_control_plane
- kube_node
- k8s_cluster
provisioner:
name: ansible
env:
@@ -21,6 +25,11 @@ provisioner:
defaults:
callbacks_enabled: profile_tasks
timeout: 120
inventory:
group_vars:
k8s_cluster:
kata_containers_enabled: true
container_manager: containerd
playbooks:
create: ../../../../../tests/cloud_playbooks/create-kubevirt.yml
prepare: ../../../molecule/prepare.yml
@@ -3,6 +3,15 @@
hosts: all
gather_facts: false
tasks:
- name: Get kubespray defaults
import_role:
name: ../../../../../kubespray_defaults
- name: Get OS facts (needed for bin_dir resolution)
setup:
gather_subset:
- '!all'
- '!min'
- 'distribution'
- name: Test version
command: "/opt/kata/bin/kata-runtime version"
register: version
@@ -7,6 +7,12 @@
- name: Get kubespray defaults
import_role:
name: ../../kubespray_defaults
- name: Get OS facts (needed for bin_dir resolution)
setup:
gather_subset:
- '!all'
- '!min'
- 'distribution'
- name: Collect services facts
ansible.builtin.service_facts:
@@ -6,6 +6,12 @@
- name: Get kubespray defaults
import_role:
name: ../../../../../kubespray_defaults
- name: Get OS facts (needed for bin_dir resolution)
setup:
gather_subset:
- '!all'
- '!min'
- 'distribution'
- name: Test version
command: "{{ bin_dir }}/youki --version"
register: youki_version
-34
View File
@@ -1,34 +0,0 @@
#!/bin/bash
set -euxo pipefail -o noglob
export LC_ALL=C.UTF-8
export LANG=C.UTF-8
_PATH='roles'
_EXCLUDE=""
while [[ $# -gt 0 ]] ; do
case $1 in
-e|--exclude)
_EXCLUDE="${_EXCLUDE} -not -path ${_PATH}/$2/*"
shift
shift
;;
-i|--include)
_PATH="${_PATH}/$2"
shift
shift
;;
-h|--help)
echo "Usage: molecule_run.sh [-h|--help] [-e|--exclude] [-i|--include]"
exit 0
;;
esac
done
for d in $(find ${_PATH} ${_EXCLUDE} -name molecule -type d)
do
pushd $(dirname $d)
molecule test --all
popd
done