---

- name: Prepare Headwind Remote
  hosts: localhost
  connection: local
  vars_files:
    - config.build.yaml
    - config.defaults.yaml
    - ../config.yaml

  tasks:
    - import_tasks: tasks_python.yaml
    - import_tasks: tasks_check_settings.yaml

    - name: Process secret for all Janus API requests
      set_fact:
        janus_api_secret: "{{ lookup('password', './dist/credentials/janus_api_secret length=8 chars={{ password_chars }}') }}"

    - name: Process secret for Janus Admin API requests
      set_fact:
        janus_admin_api_secret: "{{ lookup('password', './dist/credentials/janus_admin_api_secret length=15 chars={{ password_chars }}') }}"

    - name: Process Nginx configuration
      template:
        src: "{{ item }}"
        dest: ./dist/conf/nginx/{{ item | basename | regex_replace('\.j2$', '') }}
      with_fileglob:
        - ./templates/nginx/*.j2

    - name: Process Janus configuration
      block:
        - name: Process Janus configuration files (templated)
          template:
            src: "{{ item }}"
            dest: ./dist/conf/janus/{{ item | basename | regex_replace('\.j2$', '') }}
          with_fileglob:
            - ./templates/janus/*.j2

        - name: Process Janus configuration files
          copy:
            src: "{{ item }}"
            dest: ./dist/conf/janus/{{ item | basename }}
          with_fileglob:
            - ./templates/janus/*.jcfg

    - name: Process web-admin configuration
      template:
        src: ./templates/web-admin/settings.js.j2
        dest: ./dist/web-admin/dist/js/settings.js

    - name: Process docker-compose configuration
      template:
        src: ./templates/docker-compose/docker-compose.yaml.j2
        dest: ../docker-compose.yaml
