From 88480801bb1d83cbb105d893f4e46e74f3a3515b Mon Sep 17 00:00:00 2001 From: Christian Krause Date: Tue, 10 Oct 2023 11:20:30 +0200 Subject: [PATCH] adds molecule tests --- .github/workflows/ansible-lint.yml | 19 ----- .github/workflows/ansible.yml | 48 +++++++++++++ molecule/default/converge.yml | 10 +++ molecule/default/molecule.yml | 111 +++++++++++++++++++++++++++++ molecule/default/verify.yml | 30 ++++++++ requirements.yml | 11 +++ tasks/deps-debian.yml | 20 ------ tasks/deps-default.yml | 8 +++ tasks/deps-redhat.yml | 7 +- tasks/deps-ubuntu_18.yml | 42 +++++++++++ tasks/main.yml | 10 ++- vars/main.yml | 22 ++++++ 12 files changed, 295 insertions(+), 43 deletions(-) delete mode 100644 .github/workflows/ansible-lint.yml create mode 100644 .github/workflows/ansible.yml create mode 100644 molecule/default/converge.yml create mode 100644 molecule/default/molecule.yml create mode 100644 molecule/default/verify.yml create mode 100644 requirements.yml delete mode 100644 tasks/deps-debian.yml create mode 100644 tasks/deps-default.yml create mode 100644 tasks/deps-ubuntu_18.yml diff --git a/.github/workflows/ansible-lint.yml b/.github/workflows/ansible-lint.yml deleted file mode 100644 index e1359b1..0000000 --- a/.github/workflows/ansible-lint.yml +++ /dev/null @@ -1,19 +0,0 @@ ---- - -name: ansible-lint - -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 - -... diff --git a/.github/workflows/ansible.yml b/.github/workflows/ansible.yml new file mode 100644 index 0000000..4649d0b --- /dev/null +++ b/.github/workflows/ansible.yml @@ -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' + +... diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml new file mode 100644 index 0000000..60e2026 --- /dev/null +++ b/molecule/default/converge.yml @@ -0,0 +1,10 @@ +--- + +- name: converge + hosts: all + tasks: + - name: include the role + ansible.builtin.include_role: + name: idiv_biodiversity.lmod + +... diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml new file mode 100644 index 0000000..c5aa135 --- /dev/null +++ b/molecule/default/molecule.yml @@ -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 + +... diff --git a/molecule/default/verify.yml b/molecule/default/verify.yml new file mode 100644 index 0000000..c288684 --- /dev/null +++ b/molecule/default/verify.yml @@ -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' + +... diff --git a/requirements.yml b/requirements.yml new file mode 100644 index 0000000..7cbaea8 --- /dev/null +++ b/requirements.yml @@ -0,0 +1,11 @@ +--- + +collections: + + - name: community.general + +roles: + + - name: geerlingguy.repo-epel + +... diff --git a/tasks/deps-debian.yml b/tasks/deps-debian.yml deleted file mode 100644 index fd07fe9..0000000 --- a/tasks/deps-debian.yml +++ /dev/null @@ -1,20 +0,0 @@ ---- - -- name: 'install lmod dependencies {{ __lmod_dependencies }}' - ansible.builtin.apt: - name: '{{ __lmod_dependencies | join(",") }}' - become: yes - -# https://github.com/TACC/Lmod/commit/1d15717144f595b9a09e8421aa00b5dead3ed21d -- name: fix lua-posix on Ubuntu - 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 - when: >- - __lmod_os_version == 'ubuntu_18' - or - __lmod_os_version == 'ubuntu_20' - -... diff --git a/tasks/deps-default.yml b/tasks/deps-default.yml new file mode 100644 index 0000000..ed40c53 --- /dev/null +++ b/tasks/deps-default.yml @@ -0,0 +1,8 @@ +--- + +- name: 'install dependencies {{ __lmod_dependencies }}' + ansible.builtin.package: + name: '{{ __lmod_dependencies }}' + become: yes + +... diff --git a/tasks/deps-redhat.yml b/tasks/deps-redhat.yml index 140b079..87aaf25 100644 --- a/tasks/deps-redhat.yml +++ b/tasks/deps-redhat.yml @@ -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 ... diff --git a/tasks/deps-ubuntu_18.yml b/tasks/deps-ubuntu_18.yml new file mode 100644 index 0000000..2e0cc38 --- /dev/null +++ b/tasks/deps-ubuntu_18.yml @@ -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 + +... diff --git a/tasks/main.yml b/tasks/main.yml index d416da2..94ee764 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -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: diff --git a/vars/main.yml b/vars/main.yml index bffbea2..a02b99f 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -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: >- {{ @@ -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" + }} + ...