diff --git a/templates/pre-commit.yml b/templates/pre-commit.yml
index 29dc3b73881bcddccdc9af6603e721f04a64539e..0a389b87022eb1e635ee6a8f40d9980eb00d3339 100644
--- a/templates/pre-commit.yml
+++ b/templates/pre-commit.yml
@@ -22,7 +22,10 @@ pre-commit:
     # yamllint disable-line rule:line-length
     TF_HTTP_UNLOCK_ADDRESS: ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/terraform/state/default/lock
     TF_HTTP_UNLOCK_METHOD: DELETE
+    # Needed for locking Cython to <3 for PyYAML<6 to install properly.
+    PIP_CONSTRAINT: /tmp/constraint.txt
   script:
+    - echo 'Cython < 3.0' > "$PIP_CONSTRAINT"
     - pre-commit run --all-files
   cache:
     paths: