---

- block:
  - name: make directories
    file:
      name: "{{ item }}"
      state: directory
    with_items:
      - "{{ docker_registry_data_dir }}"
      - "{{ docker_registry_compose_dir }}"
      - "{{ docker_registry_nginx_dir }}"
      - "{{ docker_registry_ssl_dir }}"

  - name: install docker-compose.yml
    template:
      src: docker-compose.yml
      dest: "{{ docker_registry_compose_dir }}/docker-compose.yml"
    notify: restart docker-registry

  - name: install nginx conf
    copy:
      src: registry.conf
      dest: "{{ docker_registry_nginx_dir }}/registry.conf"
    notify: restart docker-registry

  - name: install registry config
    copy:
      src: config.yml
      dest: "{{ docker_registry_compose_dir }}/config.yml"
    notify: restart docker-registry

  - name: install ssl key
    copy:
      content: "{{ lookup('hashi_vault', 'secret=secret/cert/zooxlabs_wildcard').private_key }}"
      dest: "{{ docker_registry_ssl_dir }}/zooxlabs_wildcard.key"
    notify: restart docker-registry

  - name: install ssl cert
    copy:
      src: templates/zooxlabs_wildcard.crt
      dest: "{{ docker_registry_ssl_dir }}/zooxlabs_wildcard.crt"
    notify: restart docker-registry

  - name: start docker-registry
    docker_service:
      project_src: "{{ docker_registry_compose_dir }}"
      state: present

  become: yes
