yt-dlp-dags/ansible/playbook-stress-download-simulation.yml

95 lines
4.6 KiB
YAML

---
- name: "STRESS-SETUP: Manage download simulation"
hosts: workers
gather_facts: no
vars:
tmux_session_download: "{{ 'stress-download-worker-' + (worker_num | string) if (profile_prefix | default('') == 'worker' and worker_num is defined) else 'stress-download-' + (profile_prefix | default('default')) | replace(',', '-') }}"
download_policy: "policies/11_direct_docker_download_simulation.yaml"
vars_files:
- "group_vars/all/vault.yml"
pre_tasks:
- name: Set inventory_env fact
ansible.builtin.set_fact:
inventory_env: "{{ inventory_file | basename | splitext | first | replace('inventory.', '') }}"
- name: Load environment-specific variables
ansible.builtin.include_vars: "{{ item }}"
with_fileglob:
- "group_vars/all/generated_vars{{ '.' + inventory_env if inventory_env else '' }}.yml"
tasks:
- name: Define base directory for node
ansible.builtin.set_fact:
base_dir: "{{ airflow_worker_dir }}"
- name: Validate profile_prefix is provided when starting or stopping
ansible.builtin.fail:
msg: "profile_prefix is required when start_download=true or stop_download=true"
when:
- (start_download | default(false) | bool or stop_download | default(false) | bool)
- profile_prefix is not defined
- name: "Display policy being used for download simulation"
ansible.builtin.debug:
msg: "Using download simulation policy: {{ download_policy }}"
when: start_download | default(false) | bool
- name: Manage download simulation process
ansible.builtin.include_tasks:
file: manage-processes-tasks.yml
vars:
tmux_session_name: "{{ tmux_session_download }}"
working_dir: "{{ base_dir }}"
command_to_run: >
./bin/ytops-client stress-policy
--policy {{ download_policy }}
{# {% if dummy_batch | default(true) | bool %}--dummy-batch{% endif %} #}
{% if download_min_seconds is defined %}--set 'settings.dummy_simulation_settings.download_min_seconds={{ download_min_seconds }}'{% endif %}
{% if download_max_seconds is defined %}--set 'settings.dummy_simulation_settings.download_max_seconds={{ download_max_seconds }}'{% endif %}
{# --set 'execution_control.worker_pools=[{"profile_prefix": "{% if profile_prefix == 'worker' %}{{ display_prefix }}{% else %}{{ profile_prefix }}{% endif %}", "workers": 1}]' #}
{% for setting in (extra_set_args | default('[]')) | from_yaml %}--set '{{ setting }}' {% endfor %}
{% if profile_prefix == 'worker' %}--workers 1{% endif %}
--profile-prefix {% if profile_prefix == 'worker' %}{{ display_prefix }}{% else %}{{ profile_prefix }}{% endif %}
process_grep_pattern: "ytops-client.*stress-policy.*--policy {{ download_policy }}{% if profile_prefix == 'worker' %}.*--workers 1{% endif %}.*--profile-prefix {% if profile_prefix == 'worker' %}{{ display_prefix }}{% else %}{{ profile_prefix }}{% endif %}"
start_process: "{{ start_download | default(false) | bool }}"
stop_process: "{{ stop_download | default(false) | bool }}"
check_status: "{{ vars.check_status | default(false) | bool }}"
- name: List active tmux sessions
ansible.builtin.shell:
cmd: tmux list-sessions 2>/dev/null || true
register: tmux_sessions
changed_when: false
- name: Display active sessions
ansible.builtin.debug:
msg: "Active tmux sessions on {{ inventory_hostname }}: {{ tmux_sessions.stdout_lines }}"
- name: Check tmux session output for errors
block:
- name: Wait for a moment for the process to start
ansible.builtin.pause:
seconds: 2
- name: Capture tmux pane content
ansible.builtin.shell:
cmd: "tmux capture-pane -p -t {{ tmux_session_download }}"
register: tmux_output
changed_when: false
ignore_errors: true
- name: Display tmux pane content if session exists
ansible.builtin.debug:
msg: "Initial output from tmux session '{{ tmux_session_download }}':"
when: tmux_output.rc == 0
- name: Show output lines if session exists
ansible.builtin.debug:
var: tmux_output.stdout_lines
when: tmux_output.rc == 0
- name: Report if session not found
ansible.builtin.debug:
msg: "Tmux session '{{ tmux_session_download }}' was not found. It may have exited immediately upon starting."
when: tmux_output.rc != 0
when: start_download | default(false) | bool