112 lines
4.4 KiB
YAML
112 lines
4.4 KiB
YAML
---
|
|
- name: "STRESS-SETUP: Manage tmux sessions for monitoring and enforcer"
|
|
hosts: master
|
|
gather_facts: no
|
|
vars:
|
|
tmux_session_monitor: "stress-monitor"
|
|
tmux_session_enforcer: "stress-enforcer"
|
|
enforcer_policy: "policies/8_unified_simulation_enforcer.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: Manage monitor process
|
|
ansible.builtin.include_tasks:
|
|
file: manage-processes-tasks.yml
|
|
vars:
|
|
tmux_session_name: "{{ tmux_session_monitor }}"
|
|
working_dir: "{{ airflow_master_dir }}"
|
|
command_to_run: >
|
|
./bin/ytops-client profile list
|
|
--auth-env sim_auth
|
|
--download-env sim_download
|
|
--live
|
|
--no-blink
|
|
--show-reasons
|
|
process_grep_pattern: "ytops-client.*profile.*list"
|
|
start_process: "{{ start_monitor | default(false) | bool }}"
|
|
stop_process: "{{ stop_sessions | default(false) | bool or stop_monitor | default(false) | bool }}"
|
|
check_status: "{{ vars.check_status | default(false) | bool }}"
|
|
|
|
- name: Check monitor 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_monitor }}"
|
|
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_monitor }}':"
|
|
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_monitor }}' was not found."
|
|
when: tmux_output.rc != 0
|
|
when: start_monitor | default(false) | bool
|
|
|
|
- name: Manage enforcer process
|
|
ansible.builtin.include_tasks:
|
|
file: manage-processes-tasks.yml
|
|
vars:
|
|
tmux_session_name: "{{ tmux_session_enforcer }}"
|
|
working_dir: "{{ airflow_master_dir }}"
|
|
command_to_run: >
|
|
./bin/ytops-client policy-enforcer
|
|
--policy {{ enforcer_policy }}
|
|
--live
|
|
process_grep_pattern: "ytops-client.*policy-enforcer.*{{ enforcer_policy }}"
|
|
start_process: "{{ start_enforcer | default(false) | bool }}"
|
|
stop_process: "{{ stop_sessions | default(false) | bool or stop_enforcer | default(false) | bool }}"
|
|
check_status: "{{ vars.check_status | default(false) | bool }}"
|
|
|
|
- name: Check enforcer 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_enforcer }}"
|
|
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_enforcer }}':"
|
|
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_enforcer }}' was not found."
|
|
when: tmux_output.rc != 0
|
|
when: start_enforcer | 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: {{ tmux_sessions.stdout_lines }}"
|