- hosts: datacenter
  name: Install docker1
  become: true
  become_user: root
  gather_facts: false
  tasks:
    - name: Install docker
      ansible.builtin.apt:
        name: 
          - ca-certificates
          - curl 
          - telnet
          - net-tools
          - python3-pip
          - python3-dev
        state: present
        update_cache: true
    - name: Get keys for raspotify
      ansible.builtin.shell:
        install -m 0755 -d /etc/apt/keyrings
    - name: Get keys for raspotify
      ansible.builtin.shell:
        curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc
    - name: Get keys for raspotify
      ansible.builtin.shell:
        chmod a+r /etc/apt/keyrings/docker.asc

    - name: Get keys for raspotify
      ansible.builtin.shell: echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
    - name: Install docker
      ansible.builtin.apt:
        name: 
          - docker-ce
          - docker-ce-cli
          - containerd.io
          - docker-buildx-plugin
          - docker-compose-plugin
        update_cache: true

    - name: Create a directory docker.service.d
      ansible.builtin.file:
        path: /etc/systemd/system/docker.service.d/
        state: directory
        mode: '0755'
    - name: Creating a file with content
      copy:
        dest: "/etc/systemd/system/docker.service.d/override.conf"
        content: |
          [Service]
          ExecStart=
          ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock -H tcp://0.0.0.0:2375

    - name: Just force systemd to reread configs
      ansible.builtin.systemd:
        daemon_reload: true

    - name: Restart docker service
      ansible.builtin.service:
        name: docker.service
        state: restarted
        