---
- name: Install osquery on Ubuntu 20.04 LTS
  hosts: localhost
  become: yes
  gather_facts: no
  tasks:
    - name: Ensure /etc/apt/keyrings directory exists
      ansible.builtin.file:
        path: /etc/apt/keyrings
        state: directory

    - name: Download osquery public key
      ansible.builtin.get_url:
        url: https://pkg.osquery.io/deb/pubkey.gpg
        dest: /etc/apt/keyrings/osquery.asc
        mode: '0644'

    - name: Add osquery repository
      ansible.builtin.apt_repository:
        repo: 'deb [arch=amd64 signed-by=/etc/apt/keyrings/osquery.asc] https://pkg.osquery.io/deb deb main'
        state: present

    - name: Install osquery
      ansible.builtin.apt:
        name: osquery
        state: present
        update_cache: yes