Skip to content

Commit

Permalink
Add molecule testing
Browse files Browse the repository at this point in the history
  • Loading branch information
dlundgren committed Nov 22, 2024
1 parent 0af9d2b commit 6b8cf71
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 78 deletions.
40 changes: 0 additions & 40 deletions .github/workflows/ansible.yml

This file was deleted.

22 changes: 8 additions & 14 deletions .github/workflows/galaxy.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
---
#
# Ansible managed
#

name: Release to Ansible Galaxy

on:
push:
tags:
- '*'
schedule:
- cron: '1 10 14 * *'
on: # yamllint disable-line rule:truthy
workflow_dispatch:
release:
types: [published]

jobs:
release:
runs-on: ubuntu-latest
steps:
- name: galaxy
uses: robertdebock/galaxy-action@1.2.1
- name: publish to galaxy
uses: ansible-actions/ansible-galaxy-action@v1.2.0
with:
galaxy_api_key: ${{ secrets.galaxy_api_key }}
galaxy_version: ${{ github.ref_name }}
galaxy_api_key: ${{ secrets.galaxy_api_key }}
59 changes: 59 additions & 0 deletions .github/workflows/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
#
# Ansible managed
#

name: Ansible Molecule

on:
push:
tags_ignore:
- '*'
pull_request:

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v4
- name: molecule
uses: ansible/ansible-lint@main
test:
needs:
- lint
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- image: ubuntu
tag: noble
- image: amazonlinux
tag: "2023"
- image: rockylinux
tag: "8"
steps:
- name: checkout
uses: actions/checkout@v4
with:
path: "${{ github.repository }}"

- name: Set up Python 3
uses: actions/setup-python@v5
with:
python-version: '3.x'

# we specify 2.16.11 for compatibility with amazonlinux:2
- name: Install test dependencies
run: pip install molecule-docker docker requests==2.31.0 ansible-core==2.16.11

- name: molecule
run: molecule test
env:
PY_COLORS: '1'
ANSIBLE_FORCE_COLOR: '1'
image: "${{ matrix.image }}"
tag: "${{ matrix.tag }}"
working-directory: "${{ github.repository }}"

27 changes: 3 additions & 24 deletions molecule/default/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,11 @@ lint: |
yamllint molecule/default/converge.yml
ansible-lint molecule/default/converge.yml
platforms:
- name: instance
image: centos:7
# options:
# config-file: molecule/default/yaml-lint.yml
#platformsa:
# - name: ubuntu-bionic
# image: solita/ubuntu-systemd:bionic
# command: ${MOLECULE_DOCKER_COMMAND:-""}
# volumes:
# - /sys/fs/cgroup:/sys/fs/cgroup:ro
# pull: true
# privileged: true
# pre_build_image: true
# groups:
# - docker
# - name: centos
# image: milcom/centos7-systemd:latest
# privileged: true
# groups:
# - docker
- name: "ssl-cert-${image:-ubuntu}-${tag:-jammy}"
image: "${image:-ubuntu}:${tag:-jammy}"
provisioner:
name: ansible
config_options:
defaults:
stdout_callback: yaml
bin_ansible_callbacks: yes
log: False
scenario:
name: default
verifier:
Expand Down
4 changes: 4 additions & 0 deletions molecule/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
molecule[docker]
ansible-lint
yamllint
pydocker
18 changes: 18 additions & 0 deletions molecule/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
RED=$(tput setaf 1)
GREEN=$(tput setaf 2)
BLUE=$(tput setaf 4)
RESET=$(tput sgr0)

# amazonlinux:2 requires !python3 so we aren't really testing it
IMAGES=${1}
for image in ${IMAGES:=ubuntu:jammy ubuntu:noble amazonlinux:2023 rockylinux:8 rockylinux:9}; do
echo ">> ${BLUE}INFO${RESET} Testing ${image}" | tee -a molecule/test.log
tag="${image#*:}"
image="${image%%:*}" tag=${tag} pipenv run molecule test >> molecule/test.log 2>&1
if [ "$?" -ne 0 ]; then
echo "== ${RED}FAILURE${RESET} did not complete successfully" | tee -a molecule/test.log
exit 1
else
echo "== ${GREEN}SUCCESS${RESET}"
fi
done

0 comments on commit 6b8cf71

Please sign in to comment.