The lifecycle scenario runs in a Docker container without systemd as PID 1. The side_effect and verify playbooks used systemd module operations unconditionally, causing failures like: System has not been booted with systemd as init system Add a systemd availability check (/run/systemd/system stat) to both playbooks and conditionally skip systemd tasks when running in environments without systemd (e.g. Molecule Docker containers).
51 lines
1.5 KiB
YAML
51 lines
1.5 KiB
YAML
---
|
|
- name: Verify
|
|
hosts: all
|
|
become: true
|
|
vars:
|
|
runner_name: "lifecycle-test-runner"
|
|
pre_tasks:
|
|
- name: Load role defaults
|
|
ansible.builtin.include_vars:
|
|
dir: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/defaults"
|
|
tasks:
|
|
- name: Check systemd template unit exists
|
|
ansible.builtin.stat:
|
|
path: "/etc/systemd/system/gitea-runner@.service"
|
|
register: template_stat
|
|
|
|
- name: Assert template unit exists
|
|
ansible.builtin.assert:
|
|
that:
|
|
- template_stat.stat.exists
|
|
fail_msg: "Systemd template unit is missing"
|
|
|
|
- name: Check if systemd is available
|
|
ansible.builtin.stat:
|
|
path: /run/systemd/system
|
|
register: systemd_available
|
|
|
|
- name: Check instance is enabled
|
|
ansible.builtin.systemd:
|
|
name: "gitea-runner@lifecycle-test-runner"
|
|
register: service_status
|
|
when: systemd_available.stat.exists
|
|
|
|
- name: Assert instance is enabled
|
|
ansible.builtin.assert:
|
|
that:
|
|
- service_status.status.LoadState == 'loaded'
|
|
fail_msg: "Systemd instance is not loaded"
|
|
when: systemd_available.stat.exists
|
|
|
|
- name: Check instance data directory exists after lifecycle
|
|
ansible.builtin.stat:
|
|
path: "{{ gitea_runner_base_data_dir }}/{{ runner_name }}"
|
|
register: data_dir_stat
|
|
|
|
- name: Assert instance data directory exists
|
|
ansible.builtin.assert:
|
|
that:
|
|
- data_dir_stat.stat.exists
|
|
fail_msg: "Instance data directory is missing after lifecycle"
|