# SPDX-License-Identifier: MIT
---
- name: Check if elasticsearch pmda is registered
  command: pmprobe -I pmcd.agent.status
  register: status
  until: status.stdout.find("elasticsearch") != -1
  retries: 10
  delay: 1
  changed_when: false
  when: __metrics_is_booted | bool

# yamllint disable rule:line-length
- name: Set platform/version specific variables
  include_vars: "{{ item }}"
  loop:
    - roles/linux-system-roles.metrics/roles/elasticsearch/vars/default.yml"
    - roles/linux-system-roles.metrics/roles/elasticsearch/vars/{{ ansible_facts['os_family'] }}.yml"
    - roles/linux-system-roles.metrics/roles/elasticsearch/vars/{{ ansible_facts['distribution'] }}.yml"
    - roles/linux-system-roles.metrics/roles/elasticsearch/vars/{{ ansible_facts['distribution'] }}_{{ ansible_facts['distribution_major_version'] }}.yml"
    - roles/linux-system-roles.metrics/roles/elasticsearch/vars/{{ ansible_facts['distribution'] }}_{{ ansible_facts['distribution_version'] }}.yml"
  when: item is file
# yamllint enable rule:line-length

- name: Check the ansible_managed header in the configuration file
  vars:
    __test_config_path: "{{ __elasticsearch_conf_dir | d('/etc/pcp/elasticsearch') }}/elasticsearch.conf"
  include_tasks: check_header.yml
