02_run_one.ymlΒΆ

---
- name: πŸ“Œ Define per-role paths
  ansible.builtin.set_fact:
    _playwright_env_template: "{{ lookup('path_absolute', 'roles', application_id, 'templates/playwright.env.j2') }}"
    _playwright_files_dir: "{{ lookup('path_absolute', 'roles', application_id, 'files/playwright') }}"
    _playwright_spec_src: "{{ lookup('path_absolute', 'roles', application_id, 'files/playwright/playwright.spec.js') }}"
    _playwright_stage_dir: "{{ TEST_E2E_PLAYWRIGHT_STAGE_BASE_DIR }}/{{ application_id }}"
    _playwright_stage_tests_dir: "{{ TEST_E2E_PLAYWRIGHT_STAGE_BASE_DIR }}/{{ application_id }}/tests"
    _playwright_tree_archive: "/tmp/infinito-playwright-{{ application_id }}.tar"
    _playwright_reports_dir: "{{ TEST_E2E_PLAYWRIGHT_REPORTS_BASE_DIR }}/{{ application_id }}"

- name: βœ… Assert required Playwright env template exists
  ansible.builtin.stat:
    path: "{{ _playwright_env_template }}"
  register: _env_template_stat
  delegate_to: localhost
  become: false

- name: πŸ›‘ Fail if Playwright env template is missing
  ansible.builtin.fail:
    msg: "Missing Playwright env template: {{ _playwright_env_template }}"
  when: not _env_template_stat.stat.exists

- name: βœ… Assert required Playwright spec exists
  ansible.builtin.stat:
    path: "{{ _playwright_spec_src }}"
  register: _spec_stat
  delegate_to: localhost
  become: false

- name: πŸ›‘ Fail if Playwright spec is missing
  ansible.builtin.fail:
    msg: "Missing Playwright spec file: {{ _playwright_spec_src }}"
  when: not _spec_stat.stat.exists

- name: πŸ”Ž Check optional application vars file
  ansible.builtin.stat:
    path: "{{ lookup('path_absolute', 'roles', application_id, 'vars/main.yml') }}"
  register: _playwright_app_vars_stat
  delegate_to: localhost
  become: false

- name: βš™οΈ Load optional application vars
  ansible.builtin.include_vars:
    file: "{{ lookup('path_absolute', 'roles', application_id, 'vars/main.yml') }}"
  when: _playwright_app_vars_stat.stat.exists

- name: πŸ“ Recreate staging directory
  ansible.builtin.file:
    path: "{{ _playwright_stage_dir }}"
    state: absent

- name: πŸ“ Create staging directory
  ansible.builtin.file:
    path: "{{ _playwright_stage_dir }}"
    state: directory
    mode: "0755"

- name: πŸ“ Create staging tests directory
  ansible.builtin.file:
    path: "{{ _playwright_stage_tests_dir }}"
    state: directory
    mode: "0755"

- name: πŸ“„ Render package.json from template
  ansible.builtin.template: # nocheck: stack-host-template (per-host playwright stage dir, runs on every test host)
    src: "{{ _playwright_default_package_template }}"
    dest: "{{ _playwright_stage_dir }}/package.json"
    mode: "0644"

- name: πŸ“‹ Copy central default playwright.config.js
  ansible.builtin.copy:
    src: "{{ _playwright_default_config_js }}"
    dest: "{{ _playwright_stage_dir }}/playwright.config.js"
    mode: "0644"

- name: πŸ“¦ Pack the role's Playwright tree for a single transfer
  ansible.builtin.command:
    argv: [tar, -cf, "{{ _playwright_tree_archive }}", -C, "{{ _playwright_files_dir }}", .]
  delegate_to: localhost
  become: false
  changed_when: false

- name: πŸ“‹ Stage the Playwright tree and the shared helpers
  ansible.builtin.unarchive:
    src: "{{ playwright_archive }}"
    dest: "{{ _playwright_stage_tests_dir }}/"
    extra_opts: [--no-same-owner]
  loop:
    - "{{ _playwright_tree_archive }}"
    - "{{ TEST_E2E_PLAYWRIGHT_HELPERS_ARCHIVE }}"
  loop_control:
    loop_var: playwright_archive

- name: βœ… Ensure staging volume directory exists
  ansible.builtin.file:
    path: "{{ _playwright_stage_dir }}/volume"
    state: directory
    mode: "0755"

- name: πŸ“Š Collect host disk diagnostics before Playwright
  ansible.builtin.script: "{{ role_path }}/files/dump_disk_diagnostics.sh"
  changed_when: false
  when: MODE_DEBUG | bool

- name: 🎲 Pick the network this role is tested on
  ansible.builtin.set_fact:
    _playwright_network_picks: >-
      {{ _playwright_network_picks
         | combine({application_id: lookup('domain', application_id)
                   if lookup('config', application_id, 'networks.reachability.handover', False)
                   else lookup('network_siblings', lookup('domain', application_id)) | random}) }}
  when: application_id not in _playwright_network_picks

- name: 🌈 Run Playwright on the picked network
  ansible.builtin.include_tasks: 03_run_pass.yml
  vars:
    _playwright_passes: "{{ lookup('network_siblings', lookup('domain', application_id)) }}"
    _playwright_pass_domain: "{{ _playwright_network_picks[application_id] }}"
    _playwright_pass_reports_dir: >-
      {{ _playwright_reports_dir if _playwright_pass_domain == _playwright_passes[0]
         else _playwright_reports_dir ~ '+' ~ (_playwright_pass_domain | network_of) }}