---
- name: Create act_runner base directory
  ansible.builtin.file:
    path: "{{ act_runner_data_dir }}"
    state: directory
    owner: root
    group: root
    mode: "0755"
  tags: act_runner

- name: Create per-runner data directories
  ansible.builtin.file:
    path: "{{ act_runner_data_dir }}/runner-{{ item }}"
    state: directory
    owner: root
    group: root
    mode: "0755"
  loop: "{{ range(1, act_runner_count + 1) | list }}"
  tags: act_runner

- name: Deploy act_runner config
  ansible.builtin.template:
    src: config.yml.j2
    dest: "{{ act_runner_data_dir }}/config.yml"
    owner: root
    group: root
    mode: "0644"
  notify: Restart act_runner
  tags: act_runner

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

- name: Start act_runner
  community.docker.docker_compose_v2:
    project_src: "{{ act_runner_data_dir }}"
    state: present
    pull: missing
  tags: act_runner
