---
- name: Ensure backup user exists
  user:
    name: "{{ backup_user }}"
    state: present
    shell: /bin/bash

- name: Create .ssh directory
  file:
    path: /home/{{ backup_user }}/.ssh
    state: directory
    owner: "{{ backup_user }}"
    group: "{{ backup_user }}"
    mode: '0700'

- name: Copy public key to authorized_keys
  copy:
    src: "{{ public_key_path }}"
    dest: /home/{{ backup_user }}/.ssh/authorized_keys
    owner: "{{ backup_user }}"
    group: "{{ backup_user }}"
    mode: '0600'

- name: Create backups dir for mount point
  file:
    path: "{{ mount_point }}"
    state: directory
    owner: "{{ backup_user }}"
    group: "{{ backup_user }}"
    mode: '0755'
  when: mount_device is defined and mount_device != ""
