---
# Tinc install from staging area

- name: Install find directories in staging area
  find:
    paths: [ "staging/{{ inventory_hostname }}" ]
    file_type: directory 
    recurse: yes
  register: staging_directories
  delegate_to: localhost

- include: install-directory.yaml
  vars:
    _dir: "{{ item.path }}"
    _mode: "{{ item.mode }}"
  with_items: "{{ staging_directories.files | list }}"

- name: Install find files in staging area
  find:
    paths: [ "staging/{{ inventory_hostname }}" ]
    file_type: file 
    recurse: yes
  register: staging_files
  delegate_to: localhost

- name: Install copy files
  copy:
    src: "{{ item.path }}"
    dest: "{{ item.path | replace('staging/' + inventory_hostname, '', 1) }}"
    mode: "{{ item.mode }}"
    #owner: "{{ _tinc_owner }}"
    #group: "{{ _tinc_group }}"
  with_items: "{{ staging_files.files | list }}"
  become: yes
