---
# file: roles/filebeat/tasks/key.yml

- name: "make sure /etc/apt/keyrings exists"
  ansible.builtin.file:
    path: "/etc/apt/keyrings"
    state: directory

- name: "modern signature key"
  ansible.builtin.get_url:
    url: "https://artifacts.elastic.co/GPG-KEY-elasticsearch"
    dest: "/etc/apt/keyrings/elastic.asc"

- name: "repository file"
  ansible.builtin.copy:
    content: "deb [arch=amd64 signed-by=/etc/apt/keyrings/elastic.asc] https://artifacts.elastic.co/packages/{{ elastic_major_version }}/apt stable main\n"
    dest: "/etc/apt/sources.list.d/elastic.list"
  register: repo

- name: "apt update"
  ansible.builtin.apt:
    update_cache: true
  when: repo.changed
