- name: Build inj_enabled
  set_fact:
    inj_enabled: "{{ applications | inj_enabled(application_id, SRV_WEB_INJ_COMP_FEATURES_ALL) }}"

- block:
  - name: Include dependency 'srv-web-7-4-core'
    include_role:
      name: srv-web-7-4-core
    when: run_once_srv_web_7_4_core is not defined
  - include_tasks: utils/run_once.yml
  when: run_once_sys_srv_web_inj_compose is not defined

- name: "Activate Portfolio iFrame notifier for '{{ domain }}'"
  include_role:
    name:   sys-srv-web-inj-desktop
    public: true # Vars used in templates
  when: inj_enabled.desktop

- name: "Load CDN for '{{ domain }}'"
  include_role:
    name: web-svc-cdn
    public: false
  when:
  - inj_enabled.logout
  - inj_enabled.desktop
  - application_id != 'web-svc-cdn'
  - run_once_web_svc_cdn is not defined

- name: Overwritte CDN handlers with neutral handlers
  ansible.builtin.include_tasks: "{{ playbook_dir }}/tasks/utils/load_handlers.yml"
  loop:
  - svc-prx-openresty
  - docker-compose
  loop_control:
    label: "{{ item }}"
  vars:
    handler_role_name: "{{ item }}"

- name: Reinitialize 'inj_enabled' for '{{ domain }}', after modification by CDN
  set_fact:
    inj_enabled: "{{ applications | inj_enabled(application_id, SRV_WEB_INJ_COMP_FEATURES_ALL) }}"
    inj_head_features: "{{ SRV_WEB_INJ_COMP_FEATURES_ALL | inj_features('head') }}"
    inj_body_features: "{{ SRV_WEB_INJ_COMP_FEATURES_ALL | inj_features('body') }}"

- name: "Activate Corporate CSS for '{{ domain }}'"
  include_role:
    name: sys-srv-web-inj-css
  when:
  - inj_enabled.css
  - run_once_sys_srv_web_inj_css is not defined

- name: "Activate Matomo Tracking for '{{ domain }}'"
  include_role:
    name: sys-srv-web-inj-matomo
  when: inj_enabled.matomo

- name: "Activate Javascript for '{{ domain }}'"
  include_role:
    name: sys-srv-web-inj-javascript
  when: inj_enabled.javascript

- name: "Activate logout proxy for '{{ domain }}'"
  include_role:
    name: sys-srv-web-inj-logout
    public: true # Vars used in templates
  when: inj_enabled.logout
