# Fetch shadows locally because we will use them with ansbile templating
- name: find shadow configs WORKSTATION
  find:
    paths:
      - "{{ WORKSTATION_DIR }}/application/configs"
      - "{{ WORKSTATION_DIR }}/frontend/config"
      - "{{ WORKSTATION_DIR }}/public"
    patterns:
      - "*.shadow.*"
    recurse: yes
  register: shadow_files

- name: fetch each shadow config WORKSTATION
  fetch:
    src: "{{ item.path }}"
    dest: tmp/
  with_items: "{{ shadow_files.files }}"

# Build the side-by-side lists of shadow files and generated files
- name: build shadow file list WORKSTATION
  shell: "echo {{item.path}}"
  with_items: "{{ shadow_files.files }}"
  register: shadow_file_list
  delegate_to: localhost

- name: build generated file list WORKSTATION
  shell: 'echo {{item.path}} | sed -e "s/\.shadow//"'
  with_items: "{{ shadow_files.files }}"
  register: generated_file_list
  delegate_to: localhost


# Generate the configs using locally fetched shadows as the templates
- name: template the shadows with configs.yml and convert to configs WORKSTATION
  template:
    src: "{{ playbook_dir }}/tmp/localhost{{ item.0.stdout }}"
    dest: "{{ item.1.stdout }}"
  with_together:
    - "{{ shadow_file_list.results }}"
    - "{{ generated_file_list.results }}"
  delegate_to: localhost
