62 lines
2.5 KiB
YAML
62 lines
2.5 KiB
YAML
---
|
|
- name: "STRESS-SETUP: Initialize Redis with profiles and policies"
|
|
hosts: master
|
|
gather_facts: no
|
|
vars:
|
|
setup_policy: "policies/6_profile_setup_policy.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: Check if Redis is running
|
|
ansible.builtin.shell:
|
|
cmd: "redis-cli -h {{ hostvars[groups['master'][0]].ansible_host }} -p {{ redis_port }} {% if use_redis_password | default(true) | string | lower == 'true' %}-a {{ vault_redis_password }}{% endif %} ping 2>&1 | grep -q PONG"
|
|
register: redis_check
|
|
ignore_errors: yes
|
|
changed_when: false
|
|
|
|
- name: Ensure Redis is accessible
|
|
ansible.builtin.fail:
|
|
msg: "Redis is not accessible on master node. Please ensure Redis service is running on {{ hostvars[groups['master'][0]].ansible_host }}:{{ redis_port }}"
|
|
when: redis_check.rc != 0
|
|
|
|
- name: Stop any running ytops-client processes on master
|
|
ansible.builtin.shell:
|
|
cmd: ps aux | grep "[y]tops-client" | awk '{print $2}' | xargs kill -9 >/dev/null 2>&1 || true
|
|
changed_when: false
|
|
|
|
- name: "Display policy being used for Redis initialization"
|
|
ansible.builtin.debug:
|
|
msg: "Using setup policy: {{ setup_policy }}"
|
|
|
|
- name: Initialize Redis profiles and policies
|
|
ansible.builtin.shell:
|
|
cmd: |
|
|
cd {{ airflow_master_dir }}
|
|
./bin/ytops-client setup-profiles \
|
|
--policy {{ setup_policy }} \
|
|
--cleanup-all
|
|
environment:
|
|
REDIS_HOST: "{{ hostvars[groups['master'][0]].ansible_host }}"
|
|
REDIS_PORT: "{{ redis_port }}"
|
|
REDIS_PASSWORD: "{{ vault_redis_password if use_redis_password | default(true) | string | lower == 'true' else '' }}"
|
|
register: init_result
|
|
changed_when: init_result.rc == 0
|
|
|
|
- name: Display initialization result
|
|
ansible.builtin.debug:
|
|
msg: "Redis profile initialization completed successfully"
|
|
when: init_result.rc == 0
|
|
|
|
- name: Handle initialization failure
|
|
ansible.builtin.fail:
|
|
msg: "Failed to initialize Redis profiles: {{ init_result.stderr }}"
|
|
when: init_result.rc != 0
|