- name: Setup ComfyUI
  hosts: comfyui
  vars:
    podman_user: "{{ comfyui_user | default('comfyui') }}"
    podman_group: "{{ comfyui_group | default('comfyui') }}"
    podman_user_home: "{{ comfyui_home | default('/home/comfyui') }}"
    podman_extra_groups: "users"
    podman_user_pubkey: "{{ comfyui_user_pubkey | default(omit) }}"
    podman_user_folders:
      - models
      - models/checkpoints
      - models/clip
      - models/clip_vision
      - models/configs
      - models/controlnet
      - models/diffusers
      - models/diffusion_models
      - models/embeddings
      - models/gligen
      - models/hypernetworks
      - models/loras
      - models/photomaker
      - models/style_models
      - models/text_encoders
      - models/unet
      - models/upscale_models
      - models/vae
      - models/vae_approx
      - output
      - custom_nodes
      - .cache
    pods:
      - name: comfyui
        build:
          dockerfile: "{{ lookup('file', 'dockerfiles/Dockerfile.comfyui') }}"
        ports:
          - "0.0.0.0:{{ comfyui_port | default(8188) }}:8188/tcp"
        env:
          PYTORCH_CUDA_ALLOC_CONF: max_split_size_mb:512
        volumes:
          - "{{ podman_user_home }}/.cache:/home/worker/.cache:Z"
          - "{{ podman_user_home }}/models:/home/worker/models:Z"
          - "{{ podman_user_home }}/custom_nodes:/home/worker/custom_nodes:Z"
          - "{{ podman_user_home }}/output:/home/worker/output:Z"
        device:
          - "nvidia.com/gpu=all"

  tasks:
    - name: Setup Pods
      ansible.builtin.include_tasks:
        file: tasks/podman.yml
