---
- name: Create clay directories
  ansible.builtin.file:
    path: "{{ item }}"
    state: directory
    owner: root
    group: root
    mode: "0755"
  loop:
    - "{{ clay_data_dir }}"
    - "{{ clay_data_dir }}/data"
    - "{{ clay_data_dir }}/workspace"
  tags: clay

- name: Deploy Dockerfile
  ansible.builtin.copy:
    src: Dockerfile
    dest: "{{ clay_data_dir }}/Dockerfile"
    owner: root
    group: root
    mode: "0644"
  notify: Rebuild and restart clay
  tags: clay

- name: Deploy Docker Compose file
  ansible.builtin.template:
    src: docker-compose.yml.j2
    dest: "{{ clay_data_dir }}/docker-compose.yml"
    owner: root
    group: root
    mode: "0644"
  notify: Restart clay
  tags: clay

- name: Build clay image
  community.docker.docker_image:
    name: clay:local
    build:
      path: "{{ clay_data_dir }}"
    source: build
    state: present
  tags: clay

- name: Start clay
  community.docker.docker_compose_v2:
    project_src: "{{ clay_data_dir }}"
    state: present
  tags: clay
