Skip to content

Commit

Permalink
adds molecule tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wookietreiber committed Oct 11, 2023
1 parent af60262 commit 8848080
Show file tree
Hide file tree
Showing 12 changed files with 295 additions and 43 deletions.
19 changes: 0 additions & 19 deletions .github/workflows/ansible-lint.yml

This file was deleted.

48 changes: 48 additions & 0 deletions .github/workflows/ansible.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---

name: ansible

on:
pull_request:
push:
branches:
- main
- wip/next

jobs:

ansible-lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ansible/ansible-lint-action@v6

molecule:
needs:
- ansible-lint
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
distro:
- centos-7
- centos-8
- debian-buster
- debian-bullseye
- debian-bookworm
- rocky-8
- rocky-9
- ubuntu-bionic
- ubuntu-focal
- ubuntu-jammy
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: '3.x'
- run: pip3 install ansible molecule molecule-plugins[docker] docker
- run: molecule test -p ${{ matrix.distro }}
env:
PY_COLORS: '1'

...
10 changes: 10 additions & 0 deletions molecule/default/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---

- name: converge
hosts: all
tasks:
- name: include the role
ansible.builtin.include_role:
name: idiv_biodiversity.lmod

...
111 changes: 111 additions & 0 deletions molecule/default/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
---

dependency:
name: galaxy

driver:
name: docker

platforms:

- name: centos-7
image: geerlingguy/docker-centos7-ansible
command: ${MOLECULE_DOCKER_COMMAND:-""}
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
cgroupns_mode: host
privileged: yes
pre_build_image: yes

- name: centos-8
image: geerlingguy/docker-centos8-ansible
command: ${MOLECULE_DOCKER_COMMAND:-""}
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
cgroupns_mode: host
privileged: yes
pre_build_image: yes

- name: debian-buster
image: geerlingguy/docker-debian10-ansible
command: ${MOLECULE_DOCKER_COMMAND:-""}
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
cgroupns_mode: host
privileged: yes
pre_build_image: yes

- name: debian-bullseye
image: geerlingguy/docker-debian11-ansible
command: ${MOLECULE_DOCKER_COMMAND:-""}
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
cgroupns_mode: host
privileged: yes
pre_build_image: yes

- name: debian-bookworm
image: geerlingguy/docker-debian12-ansible
command: ${MOLECULE_DOCKER_COMMAND:-""}
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
cgroupns_mode: host
privileged: yes
pre_build_image: yes

- name: rocky-8
image: geerlingguy/docker-rockylinux8-ansible
command: ${MOLECULE_DOCKER_COMMAND:-""}
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
cgroupns_mode: host
privileged: yes
pre_build_image: yes

- name: rocky-9
image: geerlingguy/docker-rockylinux9-ansible
command: ${MOLECULE_DOCKER_COMMAND:-""}
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
cgroupns_mode: host
privileged: yes
pre_build_image: yes

- name: ubuntu-bionic
image: geerlingguy/docker-ubuntu1804-ansible
command: ${MOLECULE_DOCKER_COMMAND:-""}
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
cgroupns_mode: host
privileged: yes
pre_build_image: yes

- name: ubuntu-focal
image: geerlingguy/docker-ubuntu2004-ansible
command: ${MOLECULE_DOCKER_COMMAND:-""}
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
cgroupns_mode: host
privileged: yes
pre_build_image: yes

- name: ubuntu-jammy
image: geerlingguy/docker-ubuntu2204-ansible
command: ${MOLECULE_DOCKER_COMMAND:-""}
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
cgroupns_mode: host
privileged: yes
pre_build_image: yes

provisioner:
name: ansible
inventory:
group_vars:
all:
lmod_install: yes

verifier:
name: ansible

...
30 changes: 30 additions & 0 deletions molecule/default/verify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---

- name: verify
hosts: all
tasks:

- name: run some module commands
ansible.builtin.shell: >-
. /etc/profile.d/z00-lmod.sh &&
module --terse list &&
module load lmod &&
module --terse list
args:
executable: /bin/bash
changed_when: no
register: __lmod_bash_module_commands

- name: debug module commands
ansible.builtin.debug:
var: __lmod_bash_module_commands

- name: assert on module commands
ansible.builtin.assert:
that:
- not __lmod_bash_module_commands.failed
- '"No modules loaded" in __lmod_bash_module_commands.stderr_lines[0]'
- '"lmod" in __lmod_bash_module_commands.stderr_lines[1]'
success_msg: 'module list works'

...
11 changes: 11 additions & 0 deletions requirements.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---

collections:

- name: community.general

roles:

- name: geerlingguy.repo-epel

...
20 changes: 0 additions & 20 deletions tasks/deps-debian.yml

This file was deleted.

8 changes: 8 additions & 0 deletions tasks/deps-default.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---

- name: 'install dependencies {{ __lmod_dependencies }}'
ansible.builtin.package:
name: '{{ __lmod_dependencies }}'
become: yes

...
7 changes: 4 additions & 3 deletions tasks/deps-redhat.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
---

- name: install lmod dependencies
- name: 'install dependencies {{ __lmod_dependencies }}'
ansible.builtin.yum:
pkg: '{{ __lmod_dependencies | join(",") }}'
enablerepo: '{{ __lmod_os_repos | join(",") }}'
name: '{{ __lmod_dependencies }}'
enablerepo: '{{ __lmod_os_repos }}'
become: yes

...
42 changes: 42 additions & 0 deletions tasks/deps-ubuntu_18.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---

- name: 'install dependencies {{ __lmod_dependencies }}'
ansible.builtin.apt:
name: '{{ __lmod_dependencies }}'
become: yes

# -----------------------------------------------------------------------------
# bionic hacks documented here
# https://github.com/TACC/Lmod/commit/1d15717144f595b9a09e8421aa00b5dead3ed21d
# -----------------------------------------------------------------------------

- name: make lua5.3 the default
community.general.alternatives:
name: lua-interpreter
link: /usr/bin/lua
path: /usr/bin/lua5.3
priority: 130
subcommands:
- name: lua-manual
link: /usr/share/man/man1/lua.1.gz
path: /usr/share/man/man1/lua5.3.1.gz

- name: make luac5.3 the default
community.general.alternatives:
name: lua-compiler
link: /usr/bin/luac
path: /usr/bin/luac5.3
priority: 130
subcommands:
- name: lua-compiler-manual
link: /usr/share/man/man1/luac.1.gz
path: /usr/share/man/man1/luac5.3.1.gz

- name: fix lua-posix symlink
ansible.builtin.file:
src: /usr/lib/x86_64-linux-gnu/liblua5.3-posix.so
dest: /usr/lib/x86_64-linux-gnu/lua/5.3/posix.so
state: link
become: yes

...
10 changes: 9 additions & 1 deletion tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,16 @@
ansible.builtin.include_vars: >-
{{ lookup('ansible.builtin.first_found', __lmod_vars_files) }}
- name: update package cache
ansible.builtin.package:
update_cache: yes
become: yes
when:
- __lmod_virtualized

- name: install dependencies
ansible.builtin.include_tasks: 'deps-{{ __lmod_os }}.yml'
ansible.builtin.include_tasks: >-
{{ lookup('ansible.builtin.first_found', __lmod_dependency_tasks) }}
- name: check if lmod is installed
ansible.builtin.stat:
Expand Down
22 changes: 22 additions & 0 deletions vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ __lmod_vars_files:
paths:
- vars

__lmod_dependency_tasks:
files: >-
{{
__lmod_first_found |
map('regex_replace', '^', 'deps-') |
map('regex_replace', '$', '.yml') |
list
}}
paths:
- tasks

__lmod_build_dependency_tasks:
files: >-
{{
Expand Down Expand Up @@ -90,4 +101,15 @@ __lmod_canary_opt_in_path: '~/{{ lmod_canary_opt_in_file }}'

__lmod_canary_opt_out_path: '~/{{ lmod_canary_opt_out_file }}'

# -----------------------------------------------------------------------------
# other
# -----------------------------------------------------------------------------

__lmod_virtualized: >-
{{
ansible_facts.virtualization_role == "guest"
and
ansible_facts.virtualization_type == "docker"
}}
...

0 comments on commit 8848080

Please sign in to comment.