--- - name: "STRESS-SETUP: Manage full worker lifecycle based on inventory" hosts: workers gather_facts: no vars: # Default action action: "status" # Available actions: start, stop, status tasks: - name: "Start all configured generators and simulators" when: action == "start" block: - name: "Set combined profile prefixes string" ansible.builtin.set_fact: combined_prefixes: "{{ profile_prefixes | default([]) | join(',') }}" when: profile_prefixes is defined and profile_prefixes | length > 0 - name: "Start single auth generator for all profiles: {{ combined_prefixes | default('none') }}" ansible.builtin.command: >- ansible-playbook {{ playbook_dir }}/playbook-stress-auth-generator.yml -i {{ inventory_file }} --limit {{ inventory_hostname }} -e "start_generator=true" -e "profile_prefix={{ combined_prefixes }}" {% if dummy_batch is defined %}-e "dummy_batch={{ dummy_batch }}"{% endif %} {% if auth_min_seconds is defined %}-e "auth_min_seconds={{ auth_min_seconds }}"{% endif %} {% if auth_max_seconds is defined %}-e "auth_max_seconds={{ auth_max_seconds }}"{% endif %} {% if batch_size is defined %}-e "batch_size={{ batch_size }}"{% endif %} {% if create_download_tasks is defined %}-e "create_download_tasks={{ create_download_tasks }}"{% endif %} {% if formats_to_download is defined %}-e "formats_to_download={{ formats_to_download }}"{% endif %} delegate_to: localhost changed_when: true when: profile_prefixes is defined and profile_prefixes | length > 0 - name: "Start single download simulator for all profiles: {{ combined_prefixes | default('none') }}" ansible.builtin.command: >- ansible-playbook {{ playbook_dir }}/playbook-stress-download-simulation.yml -i {{ inventory_file }} --limit {{ inventory_hostname }} -e "start_download=true" -e "profile_prefix={{ combined_prefixes }}" {% if dummy_batch is defined %}-e "dummy_batch={{ dummy_batch }}"{% endif %} {% if download_min_seconds is defined %}-e "download_min_seconds={{ download_min_seconds }}"{% endif %} {% if download_max_seconds is defined %}-e "download_max_seconds={{ download_max_seconds }}"{% endif %} {% if extra_set_args is defined %}-e 'extra_set_args={{ extra_set_args | to_json }}'{% endif %} delegate_to: localhost changed_when: true when: profile_prefixes is defined and profile_prefixes | length > 0 - name: "Stop all worker generators and simulators" when: action == "stop" block: - name: Kill all tmux sessions starting with 'stress-' on this worker ansible.builtin.shell: cmd: | for session in $(tmux list-sessions -F "#{session_name}" 2>/dev/null | grep -E "^stress-"); do tmux kill-session -t "$session" done || true ignore_errors: yes changed_when: false - name: Kill all ytops-client processes on this worker ansible.builtin.shell: cmd: | # Gracefully terminate ps aux | grep "[y]tops-client.*stress-policy" | awk '{print $2}' | xargs kill >/dev/null 2>&1 || true sleep 0.5 # Force kill ps aux | grep "[y]tops-client.*stress-policy" | awk '{print $2}' | xargs kill -9 >/dev/null 2>&1 || true ignore_errors: yes changed_when: false - name: "Check status of all configured generators and simulators" when: action == "status" block: - name: "Set combined profile prefixes string" ansible.builtin.set_fact: combined_prefixes: "{{ profile_prefixes | default([]) | join(',') }}" when: profile_prefixes is defined and profile_prefixes | length > 0 - name: "Check single auth generator for all profiles: {{ combined_prefixes | default('none') }}" ansible.builtin.command: >- ansible-playbook {{ playbook_dir }}/playbook-stress-auth-generator.yml -i {{ inventory_file }} --limit {{ inventory_hostname }} -e "check_status=true" -e "profile_prefix={{ combined_prefixes }}" delegate_to: localhost changed_when: false when: profile_prefixes is defined and profile_prefixes | length > 0 register: auth_status_check - name: "Display auth generator status for {{ inventory_hostname }}" ansible.builtin.debug: var: auth_status_check.stdout_lines when: auth_status_check is defined - name: "Check single download simulator for all profiles: {{ combined_prefixes | default('none') }}" ansible.builtin.command: >- ansible-playbook {{ playbook_dir }}/playbook-stress-download-simulation.yml -i {{ inventory_file }} --limit {{ inventory_hostname }} -e "check_status=true" -e "profile_prefix={{ combined_prefixes }}" delegate_to: localhost changed_when: false when: profile_prefixes is defined and profile_prefixes | length > 0 register: download_status_check - name: "Display download simulator status for {{ inventory_hostname }}" ansible.builtin.debug: var: download_status_check.stdout_lines when: download_status_check is defined