mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-06 10:59:59 +00:00
Matomo can answer SitesManager queries with HTTP 200 carrying an error dict ({"result":"error",...}) instead of the expected site array; indexing site_check.json[0] then crashed the deploy of every app with tracking enabled (decidim). Route the mapping shape into the existing API-not-ready deferral, keeping the array path untouched. A dict passes Jinja's sequence test, so is mapping is the only reliable discriminator.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
46 lines
1.6 KiB
YAML
46 lines
1.6 KiB
YAML
---
|
||
- name: 🔧 Set matomo_site_id to Null
|
||
set_fact:
|
||
matomo_site_id:
|
||
|
||
- name: 🔧 Set fact for site ID if site already exists
|
||
set_fact:
|
||
matomo_site_id: "{{ site_check.json[0].idsite }}"
|
||
when: "site_check.json is not mapping and (site_check.json | length) > 0"
|
||
changed_when: false
|
||
|
||
- name: ➕ Add site to Matomo and get ID if not exists
|
||
uri_retry:
|
||
url: "{{ matomo_index_php_url }}"
|
||
method: POST
|
||
body: "module=API&method=SitesManager.addSite&siteName={{ matomo_site_domain }}&urls={{ matomo_site_url }}&format=json&token_auth={{ matomo_effective_token }}"
|
||
body_format: form-urlencoded
|
||
status_code: 200
|
||
return_content: true
|
||
validate_certs: true
|
||
register: add_site
|
||
when: "matomo_site_id is not defined or matomo_site_id is none"
|
||
no_log: "{{ MASK_CREDENTIALS_IN_LOGS | bool }}"
|
||
|
||
- name: 🔧 Set fact for site ID if site was added
|
||
set_fact:
|
||
matomo_site_id: "{{ add_site.json.value }}"
|
||
when: "matomo_site_id is not defined or matomo_site_id is none"
|
||
changed_when: false
|
||
|
||
- name: 📄 Load Matomo tracking JS template
|
||
set_fact:
|
||
matomo_tracking_code: "{{ lookup('template','matomo-tracking.js.j2') }}"
|
||
|
||
- name: 🗜️ Collapse Matomo code into one-liner
|
||
set_fact:
|
||
matomo_tracking_code_one_liner: "{{ matomo_tracking_code | to_one_liner }}"
|
||
|
||
- name: ➕ Append Matomo CSP hash
|
||
set_fact:
|
||
webserver_csp_hashes_extra_by_app: >-
|
||
{{ webserver_csp_hashes_extra_by_app | default({})
|
||
| add_csp_hash(application_id, 'script-src-elem', matomo_tracking_code_one_liner) }}
|
||
no_log: "{{ MASK_CREDENTIALS_IN_LOGS | bool }}"
|
||
changed_when: false
|