diff --git a/roles/singularity_deb/README.md b/roles/singularity_deb/README.md new file mode 100644 index 0000000..52be341 --- /dev/null +++ b/roles/singularity_deb/README.md @@ -0,0 +1,37 @@ +singularity +========= + +Install singularity + +Requirements +------------ + +- build-essential +- cryptsetup-bin +- git +- libgpgme-dev +- libseccomp-dev +- pkg-config +- squashfs-tools +- uuid-dev +- wget +- golang + +Role Variables +-------------- +`singularity_version` + +Example Playbook +---------------- + +See `molecule/default/converge.yml` + +License +------- + +MIT + +Author Information +------------------ + +corvus-migratorius@proton.me diff --git a/roles/singularity_deb/defaults/main.yml b/roles/singularity_deb/defaults/main.yml new file mode 100644 index 0000000..848ae9f --- /dev/null +++ b/roles/singularity_deb/defaults/main.yml @@ -0,0 +1,3 @@ +--- +singularity_deb_os_name: "jammy" +singularity_deb_version: "3.9.9" diff --git a/roles/singularity_deb/handlers/main.yml b/roles/singularity_deb/handlers/main.yml new file mode 100644 index 0000000..8e42d98 --- /dev/null +++ b/roles/singularity_deb/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for playbooks/roles/singularity diff --git a/roles/singularity_deb/meta/main.yml b/roles/singularity_deb/meta/main.yml new file mode 100644 index 0000000..dbfece5 --- /dev/null +++ b/roles/singularity_deb/meta/main.yml @@ -0,0 +1,17 @@ +--- +galaxy_info: + role_name: singularity + namespace: genlab + author: Alexander Gorelyshev + company: "Genlab, LLC" + description: "" + license: "MIT" + min_ansible_version: "2.1" + + platforms: + - name: "Ubuntu" + versions: ["jammy", "noble"] + + galaxy_tags: [] + +dependencies: [] diff --git a/roles/singularity_deb/molecule/default/converge.yml b/roles/singularity_deb/molecule/default/converge.yml new file mode 100644 index 0000000..00926de --- /dev/null +++ b/roles/singularity_deb/molecule/default/converge.yml @@ -0,0 +1,12 @@ +--- +- name: Converge + hosts: all + + pre_tasks: + - name: "Update apt cache" + ansible.builtin.apt: + update_cache: true + cache_valid_time: 3600 + + roles: + - role: "genlab.common.singularity_deb" diff --git a/roles/singularity_deb/molecule/default/molecule.yml b/roles/singularity_deb/molecule/default/molecule.yml new file mode 100644 index 0000000..d82158e --- /dev/null +++ b/roles/singularity_deb/molecule/default/molecule.yml @@ -0,0 +1,27 @@ +--- +dependency: + name: galaxy + +driver: + name: docker + +platforms: + - name: ubuntu + image: geerlingguy/docker-${MOLECULE_DISTRO:-ubuntu2404}-ansible:latest + pre_build_image: true + command: ${MOLECULE_DOCKER_COMMAND:-""} + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + cgroupns_mode: host + privileged: true + +provisioner: + name: ansible + +verifier: + name: ansible + +lint: | + set -e + yamllint . + ansible-lint . diff --git a/roles/singularity_deb/molecule/default/verify.yml b/roles/singularity_deb/molecule/default/verify.yml new file mode 100644 index 0000000..75ebb1e --- /dev/null +++ b/roles/singularity_deb/molecule/default/verify.yml @@ -0,0 +1,39 @@ +--- +- name: Verify + hosts: all + gather_facts: false + any_errors_fatal: true + + pre_tasks: + - name: "Verify | include default vars" + ansible.builtin.include_vars: + dir: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/defaults/" + extensions: ['yml'] + + tasks: + - name: "Verify | check the installed Singularity version" + register: singularity_deb_installed_version + changed_when: false + ansible.builtin.command: + cmd: singularity --version + + - name: "Verify | assert installed version correctness" + tags: singularity + vars: + installed: "{{ singularity_deb_installed_version.stdout }}" + expected: "singularity-ce version {{ singularity_deb_version }}-{{ singularity_deb_os_name }}" + ansible.builtin.assert: + that: installed == expected + success_msg: "OK, expected version present: '{{ installed }}'" + fail_msg: "Unexpected Singularity version: '{{ installed }}'" + + # - name: "Assert version correctness" + # ansible.builtin.assert: + # that: singularity_installed_version.stdout == "singularity version " + singularity_deb_version + # success_msg: "Found the expected Singularity version: '{{ singularity_version }}'" + # fail_msg: "Unexpected Sinagularity version ({{ singularity_installed_version }})" + + - name: "Verify | test Singularity deployment with a 'hello-world' job" # noqa: no-changed-when + changed_when: false + ansible.builtin.command: + cmd: "singularity --debug run shub://GodloveD/lolcow" diff --git a/roles/singularity_deb/tasks/main.yml b/roles/singularity_deb/tasks/main.yml new file mode 100644 index 0000000..f2b58b9 --- /dev/null +++ b/roles/singularity_deb/tasks/main.yml @@ -0,0 +1,43 @@ +--- +- name: "Install | install Singularity" + tags: singularity + block: + - name: "Install | get the installed Singularity version" + tags: singularity + register: singularity_deb_installed_version + changed_when: false + ansible.builtin.command: + cmd: singularity --version + + - name: "Install | assert installed version correctness" + tags: singularity + vars: + installed: "{{ singularity_deb_installed_version.stdout }}" + expected: "singularity-ce version {{ singularity_deb_version }}-{{ singularity_deb_os_name }}" + ansible.builtin.assert: + that: installed == expected + success_msg: "Expected version already present: '{{ installed }}'" + fail_msg: "Found unexpected Singularity version: '{{ installed }}'" + + rescue: + - name: "Install | download GitHub release .deb" + tags: singularity + vars: + baseurl: "github.com/sylabs/singularity/releases/download" + singver: "{{ singularity_deb_version }}" + osname: "{{ singularity_deb_os_name }}" + ansible.builtin.get_url: + url: "https://{{ baseurl }}/v{{ singver }}/singularity-ce_{{ singver }}-{{ osname }}_amd64.deb" + dest: "/tmp/singularity.deb" + mode: "0644" + + - name: "Install | install downloaded package" + tags: singularity + ansible.builtin.apt: + deb: "/tmp/singularity.deb" + + - name: "Install | clean up the .deb artifact" + tags: singularity + ansible.builtin.file: + path: "/tmp/singularity.deb" + state: absent diff --git a/roles/singularity_deb/vars/main.yml b/roles/singularity_deb/vars/main.yml new file mode 100644 index 0000000..ce5bef6 --- /dev/null +++ b/roles/singularity_deb/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for playbooks/roles/singularity