Mini-Workshop
Jelle Treep & Dawa Ometto
ITS Research Engineering. Core activities include:
uu.nl/rdm
Do you have experience with:
You can find these slides here:
Some advantages of SURF ResearchCloud:
SURF HPC cloud infrastructure:
Note about the special SURF components:
Custom components are executed on the workspace from within SRC-External.
This can lead to complications due to:
A Playbook is the main script file that will be applied on a machine managed by Ansible:
---
- name: Example component
hosts: localhost # On ResearchCloud, the target host is always simply 'localhost'.
tasks:
- name: Output some text # Every task has a name
ansible.builtin.debug: # Every task invokes some module
msg: hello world # modules have arguments
# If you save this file to `test.yml`, you can run it with: ansible-playbook -i localhost, -c local -vv test.yml
cd
to the repo directoryTry running the test playbook on a container!
podman pull ghcr.io/utrechtuniversity/src-test-workspace:ubuntu_jammy
podman run -d --name src_component_test -v $(pwd):/etc/rsc/my_component ghcr.io/utrechtuniversity/src-test-workspace:ubuntu_jammy /sbin/init
podman exec src_component_test run_component.sh /etc/rsc/my_component/playbook.yml
If you’re using Docker instead of Podman:
docker pull ghcr.io/utrechtuniversity/src-test-workspace:ubuntu_jammy
docker run --privileged -d --name src_component_test -v $(pwd):/etc/rsc/my_component ghcr.io/utrechtuniversity/src-test-workspace:ubuntu_jammy /sbin/init
docker exec src_component_test run_component.sh /etc/rsc/my_component/playbook.yml
An Ansible role is a reusable set of tasks that can be (re-)applied with distinct arguments.
An Ansible collection is a set of roles (as well as plugins and playbooks).
Both can be installed with ansible-galaxy
.
---
# Top of your playbook
- name: Example component
roles:
- role: my_local_role # from the 'roles' directory of your repo
- role: uusrc.general.uv # from a collection
vars:
uv_venvs:
- path: /tmp/test_venv
python: 3.13
uv_python_versions:
- 3.11
tasks:
# You can also include a role from within your tasks
- name: Include a role
ansible.builtin.include_role: foobar
The dependencies declared in requirements.yml
in the root of your repository will be automatically installed.
---
collections:
- name: https://github.com/UtrechtUniversity/researchcloud-items.git
type: git
version: main
roles:
- src: geerlingguy.docker
version: 6.1.0
This is simply a standard requirements file for ansible-galaxy
.
Don’t: use command
and shell
where you can use a dedicated module instead.
ansible.builtin.shell
especially can show unexpected behaviourExamples: ansible.builtin.pip
, ansible.builtin.service
Don’t: depend uncritically on external roles.
Fix dependencies to specific tags or commits for stability and security.
Do: process/sanitize incoming ResearchCloud parameters.
All parameters passed along by the ResearchCloud portal arrive in your playbook as strings:
Parsing incoming ResearchCloud parameters:
---
# Top of your playbook
- name: Example component parameters
vars:
_src_component_some_str: "{{ src_component_some_str | default('fallback value', true) | replace('\\n','\n') }}"
_src_component_some_boolean: "{{ src_component_some_boolean | default(false, true) | bool }}"
_src_component_some_dict: "{{ _src_component_some_dict | default({}, true) | from_yaml }}"
# good luck with multiline yaml/json!
tasks:
...
Do: keep your playbooks simple.
Separate concerns into roles and task files:
Including task files:
The template repo contains boilerplate for:
molecule
tests, configured especially for ResearchCloudansible-lint
Build your own!
Suggested exercise: deploy a web application and add authentication.
Ideas:
See here for more detailed exercise instructions.
Think about the steps that need to be performed, e.g:
What parameters do you need?