---
- name: Install docker install
  ansible.builtin.include_tasks: install.yml

- name: Create Docker Compose directory
  file:
    path: /opt/deploy
    state: directory
    mode: '0755'

- name: Synchorisation du folder
  synchronize:
    src: ../../../../
    dest: /opt/deploy

- name: Create directory for MongoDB keys
  file:
    path: /opt/deploy/catalogue/mongoDb/keys
    state: directory
    mode: '0755'

- name: Generate MongoDB replica set key
  command: openssl rand -base64 756
  register: mongo_key

- name: Write MongoDB replica set key to file
  copy:
    content: "{{ mongo_key.stdout }}"
    dest: /opt/deploy/catalogue/mongoDb/keys/mongo-replica-set.key
    mode: '0600'
    owner: '999'
    group: '999'

- name: Log in to the private Docker registry
  community.docker.docker_login:
    registry: "{{ docker_registry }}"
    username: "{{ docker_username }}"
    password: "{{ docker_password }}"
    reauthorize: yes

- name: Start Docker Compose services
  ansible.builtin.shell: 
    cmd: docker-compose up -d 
    chdir: /opt/deploy
