---
- name: Provision control plane
  hosts: control_plane
  become: true
  vars:
    gamecloud_user: gamecloud
    gamecloud_home: /opt/hexahost-gamecloud
  tasks:
    - name: Install base packages
      ansible.builtin.apt:
        name:
          - docker.io
          - docker-compose-plugin
          - postgresql-client
          - redis-tools
          - bind9-utils
        state: present
        update_cache: true

    - name: Create application user
      ansible.builtin.user:
        name: "{{ gamecloud_user }}"
        system: true
        create_home: false

    - name: Create application directory
      ansible.builtin.file:
        path: "{{ gamecloud_home }}"
        state: directory
        owner: "{{ gamecloud_user }}"
        group: "{{ gamecloud_user }}"
        mode: "0750"

    - name: Deploy compose stack placeholder
      ansible.builtin.copy:
        dest: "{{ gamecloud_home }}/README.txt"
        owner: "{{ gamecloud_user }}"
        group: "{{ gamecloud_user }}"
        mode: "0640"
        content: |
          Deploy the production compose stack from deploy/compose on this host.
          Required services: PostgreSQL, Redis, MinIO, API, Worker, Web, Edge Gateway.

    - name: Remind operator about DNS
      ansible.builtin.debug:
        msg: >-
          Configure DNS_PROVIDER=rfc2136 and RFC2136_* variables on the API/worker hosts.
          Join hostnames must point to the edge gateway public IP.
