---

- name: Look for legacy apt keyring
  stat:
    path: /etc/apt/trusted.gpg
  register: _trusted_gpg_keyring
  tags:
    - system
    - packages
    - nodejs
    - yarn

- name: Yarn embedded GPG key is absent
  apt_key:
    id: "86E50310"
    keyring: /etc/apt/trusted.gpg
    state: absent
  when: _trusted_gpg_keyring.stat.exists
  tags:
    - system
    - packages
    - nodejs
    - yarn

- name: Yarn GPG key is installed
  copy:
    src: yarn.asc
    dest: /etc/apt/trusted.gpg.d/yarn.asc
    mode: "0644"
    owner: root
    group: root
  tags:
    - system
    - packages
    - nodejs
    - yarn

- name: Yarn sources list is available
  apt_repository:
    repo: "deb https://dl.yarnpkg.com/debian/ stable main"
    filename: yarn
    update_cache: yes
    state: present
  tags:
    - system
    - packages
    - nodejs
    - yarn

- name: Yarn is installed
  apt:
    name: yarn
    state: present
  tags:
    - packages
    - nodejs
    - yarn
