---
- name: enable repo from download.ceph.com
  block:
    - name: prevent ceph certificate error
      apt:
        name: ca-certificates
        state: latest
        update_cache: yes
      register: result
      until: result is succeeded

    - name: configure ceph community repository stable key
      apt_key:
        url: "{{ ceph_stable_key }}"
        state: present

    - name: configure Ceph community repository
      apt_repository:
        repo: "deb {{ ceph_mirror }}/debian-{{ ceph_release }}/ {{ ansible_facts['distribution_release'] }} main"
        state: present
        filename: ceph
        update_cache: no

- name: install prerequisites packages
  apt:
    name: "{{ dist_packages }}"
    state: latest
    update_cache: yes
  register: result
  until: result is succeeded

- name: install ceph packages
  apt:
    name: "{{ ceph_pkgs }}"
    state: present
    update_cache: yes 
  register: result
  until: result is succeeded

- name: install container engine
  block:
    - name: install docker
      block:
        - name: uninstall old version packages
          apt:
            name: "{{ item }}"
            state: absent
          loop: "{{ docker_old_packages }}"

        - name: configure docker repository key
          apt_key:
            url: "{{ docker_key }}"
            state: present

        - name: setup docker repository
          apt_repository:
            repo: "{{ docker_repo }}"
            state: present
            filename: docker
            update_cache: no

        - name: install docker
          apt:
            name: "{{ item }}"
            state: present
            update_cache: yes
          register: result
          until: result is succeeded
          loop: "{{ docker_packages }}"
