From 658152088e11b9bf9c8e0c561cafa677537ba0e3 Mon Sep 17 00:00:00 2001 From: Ryan Westfall Date: Wed, 16 Sep 2026 08:21:29 -0700 Subject: [PATCH] Treat omitted host_apps.enabled as true (#36) Closes #35. ## Summary - `#33` used Jinja `rejectattr('enabled', 'equalto', false)` to skip stopped apps. That filter **requires** the key, so every `host_apps` row that omits `enabled` (the documented default) crashed deploy on all webservers before git/compose. - Filter with `item.enabled | default(true)` instead, in `app-deploy` and `web-static`. `print_forge` (`enabled: false`) still skipped. `url_shortening_service` and every other omitted-key row deploy again. ## Test plan - [ ] `ansible-playbook playbooks/deploy-apps.yml --syntax-check` - [ ] Redeploy `url_shortening_service` beta: `deploy.sh --app url_shortening_service --env beta --ref ` - [ ] Confirm `print_forge` is still not started (no compose up on 8007/8019) Reviewed-on: https://git.aimloperations.com/ai_ml_operations/server-infra/pulls/36 --- IMPLEMENTATION.md | 3 ++- roles/app-deploy/tasks/main.yml | 14 ++++++++++++-- roles/web-static/tasks/main.yml | 13 ++++++++++++- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/IMPLEMENTATION.md b/IMPLEMENTATION.md index fd7ece5..88c0c41 100644 --- a/IMPLEMENTATION.md +++ b/IMPLEMENTATION.md @@ -250,7 +250,8 @@ a DB. Optional `compose_profiles: [worker]` activates docker compose profiles on that host only (used for `monica_site` / `college_craft` / `print_forge` dj-queue singleton on adama). Optional `enabled: false` skips deploy (CI included) but keeps the row for ports - and `stop.sh`. Omit the key (or `true`) to deploy as before. + and `stop.sh`. Omit the key (or `true`) to deploy as before. Do not use Jinja + `rejectattr('enabled')` — missing key is an error, not "enabled". - Django app = one compose project per env: project name `_`, host port from `host_apps`. Ports match across app hosts so NPM can balance `adama:PORT` + `roslin:PORT` + `starbuck:PORT` + `apollo:PORT`. diff --git a/roles/app-deploy/tasks/main.yml b/roles/app-deploy/tasks/main.yml index 3fc4b21..4989988 100644 --- a/roles/app-deploy/tasks/main.yml +++ b/roles/app-deploy/tasks/main.yml @@ -35,14 +35,24 @@ - app_env is defined - matching_host_apps | length == 0 +# rejectattr('enabled', …) raises when the key is omitted. Omit = enabled (#35). +- name: Reset deploy targets + ansible.builtin.set_fact: + deploy_targets: [] + - name: "Drop disabled host_apps (enabled: false)" ansible.builtin.set_fact: - deploy_targets: "{{ matching_host_apps | rejectattr('enabled', 'equalto', false) | list }}" + deploy_targets: "{{ deploy_targets + [item] }}" + loop: "{{ matching_host_apps }}" + when: item.enabled | default(true) + loop_control: + label: "{{ item.name }}/{{ item.env }}" - name: Show skipped disabled apps ansible.builtin.debug: msg: "skip disabled {{ item.name }}/{{ item.env }} on {{ inventory_hostname }}" - loop: "{{ matching_host_apps | selectattr('enabled', 'equalto', false) | list }}" + loop: "{{ matching_host_apps }}" + when: not (item.enabled | default(true)) loop_control: label: "{{ item.name }}/{{ item.env }}" diff --git a/roles/web-static/tasks/main.yml b/roles/web-static/tasks/main.yml index d5ece40..2e86d9a 100644 --- a/roles/web-static/tasks/main.yml +++ b/roles/web-static/tasks/main.yml @@ -6,9 +6,20 @@ ansible.builtin.set_fact: _node_names: "{{ app_catalog | dict2items | selectattr('value.type', 'equalto', 'node-static') | map(attribute='key') | list }}" +# rejectattr('enabled', …) raises when the key is omitted. Omit = enabled (#35). +- name: web-static | reset static apps + ansible.builtin.set_fact: + _static_apps: [] + - name: web-static | this host's static apps ansible.builtin.set_fact: - _static_apps: "{{ host_apps | default([]) | rejectattr('enabled', 'equalto', false) | selectattr('name', 'in', _node_names) | list }}" + _static_apps: "{{ _static_apps + [item] }}" + loop: "{{ host_apps | default([]) }}" + when: + - item.name in _node_names + - item.enabled | default(true) + loop_control: + label: "{{ item.name }}/{{ item.env }}" - name: web-static | configure and run when: _static_apps | length > 0