---
- name: Add ElasticSearch OSS repository
  yum_repository:
    name: elasticsearch-oss
    file: elasticsearch
    description: ElasticSearch OSS
    baseurl: https://artifacts.elastic.co/packages/oss-{{ es_major_version }}.x/yum
    gpgcheck: True
    repo_gpgcheck: True
    gpgkey: https://artifacts.elastic.co/GPG-KEY-elasticsearch
  tags: repo,logs

- name: Handle Elasticsearch (non OSS) repository
  yum_repository:
    name: elasticsearch
    file: elasticsearch
    description: ElasticSearch
    baseurl: https://artifacts.elastic.co/packages/{{ es_major_version }}.x/yum
    gpgcheck: True
    repo_gpgcheck: True
    gpgkey: https://artifacts.elastic.co/GPG-KEY-elasticsearch
    state: absent
  tags: repo,logs
