---

- name: Look for legacy apt keyring
  stat:
    path: /etc/apt/trusted.gpg
  register: _trusted_gpg_keyring

- name: NewRelic embedded GPG key is absent
  apt_key:
    id: "548C16BF"
    keyring: /etc/apt/trusted.gpg
    state: absent
  when: _trusted_gpg_keyring.stat.exists

- name: Add NewRelic GPG key
  copy:
    src: newrelic.asc
    dest: /etc/apt/trusted.gpg.d/newrelic.asc
    force: yes
    mode: "0644"
    owner: root
    group: root

- name: Install NewRelic repository
  apt_repository:
    repo: "deb http://apt.newrelic.com/debian/ newrelic non-free"
    state: present
    filename: newrelic
    update_cache: yes
