---
- block:
    - name: Seek for existing tor aths ssh files
      find:
        paths:
          - "{{ playbook_dir }}"
        patterns:
          - '*ssh-aths'
      register: find_ssh_aths_result

    - name: Delete any aths ssh files found
      file:
        state: absent
        name: "{{ item.path }}"
      with_items: "{{ find_ssh_aths_result.files }}"
      register: aths_deletion_results

  delegate_to: localhost
  become: no
  run_once: yes

- name: Force a reboot conditionally, when tor_over_ssh status changed
  command: shutdown -r now
  when: aths_deletion_results|changed

- name: Provide helpful user message and end early
  fail:
    msg: |
      Due to the transition from ssh-over-tor to ssh-over-localnet
      please re-run `./securedrop-admin install` again to continue
      re-configuration.
  when: aths_deletion_results|changed

---
- block:
    - name: Seek for existing tor aths ssh files
      find:
        paths:
          - "{{ playbook_dir }}"
        patterns:
          - '*ssh-aths'
          - '*ssh.auth_private'
      register: find_ssh_aths_result

    - name: Delete any aths ssh files found
      file:
        state: absent
        name: "{{ item.path }}"
      with_items: "{{ find_ssh_aths_result.files }}"
      register: aths_deletion_results

  delegate_to: localhost
  become: no
  run_once: yes

- name: Force a reboot conditionally, when tor_over_ssh status changed
  shell: sleep 2 && shutdown -r now
  async: 1
  poll: 0
  when: aths_deletion_results|changed

- name: Provide helpful user message and end early
  fail:
    msg: |
      Due to the transition from ssh-over-tor to ssh-over-localnet
      please run `./securedrop-admin tailsconfig` and then re-run
      `./securedrop-admin install` again to continue re-configuration.
  when: aths_deletion_results|changed

Remove v3 onion secrets when transitioning to ssh over local
Remove v3 onion secrets when transitioning to ssh over local

- v2 aths secret file pattern does not match the one for v3
- Use async task for reboot for more immediate feedback
- Instruct admin to run tailsconfig to update the ssh config on tails workstation
