# SPDX-FileCopyrightText: 2024 Slavi Pantaleev
#
# SPDX-License-Identifier: AGPL-3.0-or-later

---

- name: Check if the Docker apt repository file exists
  ansible.builtin.stat:
    path: "{{ matrix_playbook_migration_docker_trusted_gpg_d_migration_repository_path }}"
  register: matrix_playbook_migration_docker_trusted_gpg_d_migration_repository_path_status

- when: matrix_playbook_migration_docker_trusted_gpg_d_migration_repository_path_status.stat.exists | bool
  block:
    - name: Read repository file
      ansible.builtin.slurp:
        path: "{{ matrix_playbook_migration_docker_trusted_gpg_d_migration_repository_path }}"
      register: matrix_playbook_migration_docker_trusted_gpg_d_migration_repository_path_content

    - name: Remove Docker apt repository file if old key path found
      when: "'/etc/apt/trusted.gpg.d/docker.asc' in matrix_playbook_migration_docker_trusted_gpg_d_migration_repository_path_content.content | b64decode"
      ansible.builtin.file:
        path: "{{ matrix_playbook_migration_docker_trusted_gpg_d_migration_repository_path }}"
        state: absent
