---
# Docker installation and configuration

- name: Add Docker repository
  yum_repository:
    name: docker-ce
    description: Docker CE Repository
    baseurl: https://download.docker.com/linux/centos/$releasever/$basearch/stable
    gpgcheck: yes
    gpgkey: https://download.docker.com/linux/centos/gpg
    enabled: yes

- name: Install Docker
  yum:
    name:
      - docker-ce
      - docker-ce-cli
      - containerd.io
      - docker-compose-plugin
    state: present

- name: Start and enable Docker
  service:
    name: docker
    state: started
    enabled: yes

- name: Add opc user to docker group
  user:
    name: opc
    groups: docker
    append: yes

- name: Create docker network for services
  docker_network:
    name: undateable-net
    driver: bridge

- name: Login to OCIR
  docker_login:
    registry: "{{ ocir_url }}"
    username: "{{ lookup('env', 'OCIR_USERNAME') | default('idd2oizp8xvc/ryan', true) }}"
    password: "{{ lookup('env', 'OCIR_AUTH_TOKEN') }}"
  when: lookup('env', 'OCIR_AUTH_TOKEN') != ''
  ignore_errors: yes
