Integrating test-molecule role commit b90b020ad2
Some checks failed
Gitea Actions - molecule test work / Explore-molecule-Gitea-Action (push) Failing after 25s

This commit is contained in:
Mike Holloway 2025-01-04 17:44:27 -05:00
parent 004d301f66
commit 7c86412b04
6 changed files with 130 additions and 59 deletions

View File

@ -6,6 +6,7 @@ jobs:
Explore-molecule-Gitea-Action: Explore-molecule-Gitea-Action:
env: env:
ANSIBLE_ROLES_PATH: '/workspace/seasharp/ansible-role_podman-host' ANSIBLE_ROLES_PATH: '/workspace/seasharp/ansible-role_podman-host'
# ANSIBLE_REMOTE_TMP: '/root/.ansible/tmp/'
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Project Checkout - name: Project Checkout
@ -16,7 +17,5 @@ jobs:
uses: actions/setup-python@v2 uses: actions/setup-python@v2
- name: Molecule test - name: Molecule test
run: | run: |
pip install molecule-docker
ansible-galaxy collection install community.general
cd podman-host/extensions cd podman-host/extensions
molecule test molecule test

View File

@ -1,10 +1,26 @@
--- ---
- name: Converge - name: Fail if molecule group is missing
hosts: all hosts: localhost
become: true
become_user: root
gather_facts: false
tasks: tasks:
- name: podman-host Role - name: Print some info
ansible.builtin.debug:
msg: "{{ groups }}"
- name: Assert group existence
ansible.builtin.assert:
that: "'molecule' in groups"
fail_msg: |
molecule group was not found inside inventory groups: {{ groups }}
- name: Converge
hosts: molecule
# We disable gather facts because it would fail due to our container not
# having python installed. This will not prevent use from running 'raw'
# commands. Most molecule users are expected to use containers that already
# have python installed in order to avoid notable delays installing it.
tasks:
- name: Apply test-molecule Role
include_role: include_role:
name: podman-host name: test-molecule
# ansible.builtin.assert:
# that: result.stdout | regex_search("^Linux")

View File

@ -3,33 +3,80 @@
hosts: localhost hosts: localhost
connection: local connection: local
gather_facts: false gather_facts: false
# no_log: "{{ molecule_no_log }}" vars:
molecule_inventory:
all:
hosts: {}
molecule: {}
tasks: tasks:
# TODO: Developer must implement and populate 'server' variable - name: Create a container
community.docker.docker_container:
name: "{{ item.name }}"
image: "{{ item.image }}"
state: started
command: sleep 1d
log_driver: json-file
register: result
loop: "{{ molecule_yml.platforms }}"
- name: Create instance config - name: Print some info
when: server.changed | default(false) | bool # noqa no-handler ansible.builtin.debug:
block: msg: "{{ result.results }}"
- name: Populate instance config dict # noqa jinja
ansible.builtin.set_fact:
instance_conf_dict: {}
# instance': "{{ }}",
# address': "{{ }}",
# user': "{{ }}",
# port': "{{ }}",
# 'identity_file': "{{ }}", }
with_items: "{{ server.results }}"
register: instance_config_dict
- name: Convert instance config dict to a list - name: Fail if container is not running
ansible.builtin.set_fact: when: >
instance_conf: "{{ instance_config_dict.results | map(attribute='ansible_facts.instance_conf_dict') | list }}" item.container.State.ExitCode != 0 or
not item.container.State.Running
ansible.builtin.include_tasks:
file: tasks/create-fail.yml
loop: "{{ result.results }}"
loop_control:
label: "{{ item.container.Name }}"
- name: Dump instance config - name: Add container to molecule_inventory
ansible.builtin.copy: vars:
content: | inventory_partial_yaml: |
# Molecule managed all:
children:
molecule:
hosts:
"{{ item.name }}":
ansible_connection: community.docker.docker
ansible.builtin.set_fact:
molecule_inventory: >
{{ molecule_inventory | combine(inventory_partial_yaml | from_yaml, recursive=true) }}
loop: "{{ molecule_yml.platforms }}"
loop_control:
label: "{{ item.name }}"
{{ instance_conf | to_json | from_json | to_yaml }} - name: Dump molecule_inventory
dest: "{{ molecule_instance_config }}" ansible.builtin.copy:
mode: "0600" content: |
{{ molecule_inventory | to_yaml }}
dest: "{{ molecule_ephemeral_directory }}/inventory/molecule_inventory.yml"
mode: "0600"
- name: Force inventory refresh
ansible.builtin.meta: refresh_inventory
- name: Fail if molecule group is missing
ansible.builtin.assert:
that: "'molecule' in groups"
fail_msg: |
molecule group was not found inside inventory groups: {{ groups }}
run_once: true # noqa: run-once[task]
# we want to avoid errors like "Failed to create temporary directory"
- name: Validate that inventory was refreshed
hosts: molecule
gather_facts: false
tasks:
- name: Check uname
ansible.builtin.raw: uname -a
register: result
changed_when: false
- name: Display uname info
ansible.builtin.debug:
msg: "{{ result.stdout }}"

View File

@ -1,24 +1,20 @@
--- ---
- name: Destroy - name: Destroy molecule containers
hosts: localhost hosts: molecule
connection: local
gather_facts: false gather_facts: false
# no_log: "{{ molecule_no_log }}"
tasks: tasks:
# Developer must implement. - name: Stop and remove container
delegate_to: localhost
community.docker.docker_container:
name: "{{ inventory_hostname }}"
state: absent
auto_remove: true
# Mandatory configuration for Molecule to function. - name: Remove dynamic molecule inventory
hosts: localhost
- name: Populate instance config gather_facts: false
ansible.builtin.set_fact: tasks:
instance_conf: {} - name: Remove dynamic inventory file
ansible.builtin.file:
- name: Dump instance config path: "{{ molecule_ephemeral_directory }}/inventory/molecule_inventory.yml"
ansible.builtin.copy: state: absent
content: |
# Molecule managed
{{ instance_conf | to_json | from_json | to_yaml }}
dest: "{{ molecule_instance_config }}"
mode: "0600"
when: server.changed | default(false) | bool # noqa no-handler

View File

@ -2,7 +2,11 @@
dependency: dependency:
name: galaxy name: galaxy
driver: driver:
name: docker options:
managed: false
login_cmd_template: "docker exec -it {instance} bash"
ansible_connection_options:
ansible_connection: docker
platforms: platforms:
- name: instance - name: instance
image: geerlingguy/docker-rockylinux9-ansible:latest image: geerlingguy/docker-rockylinux9-ansible:latest
@ -11,10 +15,6 @@ platforms:
- /sys/fs/cgroup:/sys/fs/cgroup:ro - /sys/fs/cgroup:/sys/fs/cgroup:ro
privileged: true privileged: true
pre_build_image: true pre_build_image: true
provisioner:
name: ansible
verifier:
name: ansible
# you might want to add your own variables here based on what provisioning # you might want to add your own variables here based on what provisioning
# you are doing like: # you are doing like:
# image: quay.io/centos/centos:stream8 # image: quay.io/centos/centos:stream8

View File

@ -0,0 +1,13 @@
- name: Retrieve container log
ansible.builtin.command:
cmd: >-
{% raw %}
docker logs
{% endraw %}
{{ item.stdout_lines[0] }}
changed_when: false
register: logfile_cmd
- name: Display container log
ansible.builtin.fail:
msg: "{{ logfile_cmd.stderr }}"