---
- name: Setup
  include_tasks: setup.yml

- name: Create a temporary directory for backup files
  tempfile:
    state: directory
  register: __ssh_test_backup
  changed_when: false
  when:
    - ssh_test_backup_skip is not defined

- name: Backup files
  shell: >
    if test -f {{ item }}; then
      mkdir -p {{ __ssh_test_backup.path }}/$(dirname {{ item }});
      cp -a {{ item }} {{ __ssh_test_backup.path }}/$(dirname {{ item }})
    fi
  changed_when: false
  loop: "{{ __ssh_test_backup_files | d([]) }}"
  when:
    - __ssh_test_backup is defined
    - __ssh_test_backup.path is defined
